Manually setting the authored date in a git commit

Posted by Tim Connor Mon, 13 Oct 2008 05:04:00 GMT

After my last post about splitting and otherwise reworking git commits via rebase I needed a way to manually set the authored date on a git commit, since I had overwritten that on some old commits. And having earlier commits come a month after later ones looks a bit silly. So I searched around in vain for how to set that field manually.

Thankfully, deskin on #git was able to quickly point me in the right direction. The docs for git-commit-tree talk about the environmental variables that determine the date, author, etc. Git commit honors these (at it probably actually uses git-commit-tree, behind the scenes). So to change the date on a commit (in the middle of a git-rebase, git-reset just set the environmental variable inline, thus (if you use bash):


GIT_AUTHOR_DATE=‘2008-09-29 01:09:07’ git commit

This will not work on an —amend, though, since that is intended to just keep the same time and other settings for the commit, but just add some more changes. These means to change the time you must follow the more complicated workflow in my previous post.

Leave a comment

Comments