Git interactive rebase (fixup) preserving original date/time stamps on combined commit

554 views Asked by At

I'd like to clean up a git repo (github hosted) by git rebase and combining like commits into a single one using the 'fixup' option.
My repo goes back 3 years so I figured I could do this step-wise.
For example, my most recent 5 commits are all OK but the 6th-10th needs to be combined into a single one. So I do this:

git rebase -i @~10

That lists them in reverse order and the 10th commit is the one I want to pick.
The next 4 commits are all 'fixup'.
And the remaining 5 are set to 'pick'.

When I finish, I run:

git push origin +master

The problem is that although the commits are combined, the date shown in github's code view is today's.
I want to simply combine them retaining the date/time stamp on the original commit. Is this possible?

1

There are 1 answers

3
VonC On

A possible workaround is to use the --committer-date-is-author-date option when using git rebase... but it is not compatible with an interactive rebase.

So you can try and:

  • do your interactive rebase,
  • then, once the rebase is done, make a git filter-branch to restore the commit dates:

    git filter-branch --env-filter 'GIT_COMMITTER_DATE=$GIT_AUTHOR_DATE; export GIT_COMMITTER_DATE'