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

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

    How to Edit Multiple Commit Dates

    Other answers aren't very convenient for editing several commit dates. I've come back to this question after a few years to share a technique.

    To change the dates of the last 4 commits:

    git rebase -i HEAD~4
    

    Edit the rebase as follows, inserting exec lines to modify dates as needed:

    pick 4ca564e Do something
    exec git commit --amend --no-edit --date "1 Oct 2019 12:00:00 PDT"
    pick 1670583 Add another thing
    exec git commit --amend --no-edit --date "2 Oct 2019 12:00:00 PDT"
    pick b54021c Add some tests
    exec git commit --amend --no-edit --date "3 Oct 2019 12:00:00 PDT"
    pick e8f6653 Fix the broken thing
    exec git commit --amend --no-edit --date "4 Oct 2019 12:00:00 PDT"
    

提交回复
热议问题