views:

2336

answers:

2

The answers to this question describe a way to amend previous commit messages that haven't yet been pushed upstream. The new messages inherit the timestamps of the original commits. This seems logical, but is there a way to also re-set the times?

A: 

I had an idea to use git rebase -i with GIT_AUTHOR_DATE when editing an old commit, but it looks as though that doesn't work. What might be going on is that whatever the git commit --amend does to preserve the original commit date overrides whatever might be in GIT_AUTHOR_DATE.

Greg Hewgill
+13  A: 

use git filter-branch with an env filter that sets GIT_AUTHOR_DATE and GIT_COMMITTER_DATE for the specific hash of the commit you're looking to fix.

This will invalidate that and all future hashes.

Edited for example

If you wanted to change the dates of commit 119f9ecf58069b265ab22f1f97d2b648faf932e0, you could do so with something like this:

git filter-branch --env-filter \
    'if [ $GIT_COMMIT = 119f9ecf58069b265ab22f1f97d2b648faf932e0 ]
     then
         export GIT_AUTHOR_DATE="Fri Jan 2 21:38:53 2009 -0800"
         export GIT_COMMITTER_DATE="Sat May 19 01:01:01 2007 -0700"
     fi'
Dustin
Can you provide a specific example?
1800 INFORMATION