Update June 2014: David Fraser mentions in the comments a solution also detailed in "Change timestamps while rebasing git branch", using the option --committer-date-is-author-date
(introduced initially in Jan. 2009 in commit 3f01ad6
Note that the --committer-date-is-author-date
option seems to leave the author timestamp, and set the committer timestamp to be the same as the original author timestamp, which is what the OP Olivier Verdier wanted.
I found the last commit with the correct date and did:
git rebase --committer-date-is-author-date SHA
See git am
:
--committer-date-is-author-date
By default the command records the date from the e-mail message as the commit author date, and uses the time of commit creation as the committer date.
This allows the user to lie about the committer date by using the same value as the author date.
Note: with Git 2.29 (Q4 2020), git rebase --committer-date-is-author-date
or --ignore-date
will also work with:
- interactive rebase (
rebase -i
/rebase --interactive
)
- for the root commit (
git rebase --root
)
See "Change timestamps while rebasing git branch".
(Original answer, June 2012)
You could try, for a non-interactive rebase
(see just above: with Git 2.29, Q4 2020, that will work with an interactive rebase as well)
git rebase --ignore-date
(from this SO answer)
This is passed to git am
, which mentions:
--ignore-date
By default the command records the date from the e-mail message as the commit author date, and uses the time of commit creation as the committer date.
This allows the user to lie about the author date by using the same value as the committer date.
For git rebase
, this option is "Incompatible with the --interactive option."
Since you can change at will the timestamp of old commit date (with git filter-branch
), I suppose you can organize your Git history with whatever commit date order you want/need, even set it to the future!.
As Olivier mentions in his question, the author date is never changed by a rebase;
From the Pro Git Book:
- The author is the person who originally wrote the work,
- whereas the committer is the person who last applied the work.
So, if you send in a patch to a project and one of the core members applies the patch, both of you get credit.
To be extra clear, in this instance, as Olivier comments:
the --ignore-date
does the opposite of what I was trying to achieve!
Namely, it erases the author's timestamp and replace them with the commits timestamps!
So the right answer to my question is:
Do not do anything, since git rebase
does actually not change authors' timestamps by default.
As DylanYoung adds in the comments, using "How to identify conflicting commits by hash during git rebase?":
Using the SEQUENCE_EDITOR
variable and rebase interactive, you would just loop over the current todo
list and add a command setting the GIT_COMMITER_DATE
to the date of the original commit before each commit in the todo
.
It's a bit less fiddly because you have the list of original commits to start with (you don't have to hack into git internals to find it), but a bit more work because you have to handle the entire list at once. –
Once you're able to identify the original commit you can do something like:
git rebase -x 'GIT_COMMITTER_DATE="git show -s --format=%ci ``get_current_commit``" git commit --amend --no-edit