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

后端 未结 21 2701
慢半拍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条回答
  •  猫巷女王i
    2020-11-22 08:59

    If you want to perform the accepted answer (https://stackoverflow.com/a/454750/72809) in standard Windows command line, you need the following command:

    git filter-branch -f --env-filter "if [ $GIT_COMMIT = 578e6a450ff5318981367fe1f6f2390ce60ee045 ]; then export GIT_AUTHOR_DATE='2009-10-16T16:00+03:00'; export GIT_COMMITTER_DATE=$GIT_AUTHOR_DATE; fi"
    

    Notes:

    • It may be possible to split the command over multiple lines (Windows supports line splitting with the carret symbol ^), but I didn't succeed.
    • You can write ISO dates, saving a lot of time finding the right day-of-week and general frustration over the order of elements.
    • If you want the Author and Committer date to be the same, you can just reference the previously set variable.

    Many thanks go to a blog post by Colin Svingen. Even though his code didn't work for me, it helped me find the correct solution.

提交回复
热议问题