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

后端 未结 21 2419
慢半拍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:45

    You can do an interactive rebase and choose edit for the commit whose date you would like to alter. When the rebase process stops for amending the commit you type in for instance:

    git commit --amend --date="Wed Feb 16 14:00 2011 +0100"
    

    Afterwards you continue your interactive rebase.

    UPDATE (in response to the comment of studgeek): to change the commit date instead of the author date:

    GIT_COMMITTER_DATE="Wed Feb 16 14:00 2011 +0100" git commit --amend
    

    The lines above set an environment variable GIT_COMMITTER_DATE which is used in amend commit.

    Everything is tested in Git Bash.

提交回复
热议问题