How can one change the timestamp of an old commit in Git?

后端 未结 21 2737
慢半拍i
慢半拍i 2020-11-22 08:36

The answers to How to modify existing, unpushed commits? describe a way to amend previous commit messages that haven\'t yet been pushed upstream. The new messages inherit t

21条回答
  •  面向向阳花
    2020-11-22 08:53

    If you want to get the exact date of another commit (say you rebase edited a commit and want it to have the date of the original pre-rebase version):

    git commit --amend --date="$(git show -s --format=%ai a383243)"
    

    This corrects the date of the HEAD commit to be exactly the date of commit a383243 (include more digits if there are ambiguities). It will also pop up an editor window so you can edit the commit message.

    That's for the author date which is what you care for usually - see other answers for the committer date.

提交回复
热议问题