3

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?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250

1 Answers1

4

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'
    
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you for the suggestion. I need to read about filter-branch you suggested. Perhaps we can take a step backwards: is there an easier way to accomplish my goal of going through my commit history and combining minor ones into a single commit retaining the date/time stamp of the original? – Richard Dragon Dec 18 '16 at 16:06
  • @RichardDragon not really: you could first do a rebase interactive, then a second rebase for the most recent commits (which were not combined) with the `--committer-date-is-author-date`. – VonC Dec 18 '16 at 16:07
  • Great, your suggestion seems to be working for me, thank you! – Richard Dragon Dec 18 '16 at 16:23