How do I squash commits in git with a commit date that is not in the past?

Hack: You can use

git commit --amend --reset-author

The git commit man page says that this "also renews the author timestamp". You don't have to make any changes to the commit (I tried it locally), and it will update the timestamp to the current time. Definitely kind of an abuse, but it seems to work.


git commit --amend --date="now"

Or, if you do not want to edit the commit message:

git commit --amend --date="now" --no-edit

By default, amend will update the Committer date to the current time, but leave the Author commit date untouched.
--date="now" will also set the Author commit date to the current time.

Why does it matter if Author and Committer date are different?
When doing a git log, by default the Author date is shown (git log --format=fuller shows the Committer date).
What may be unexpected, however, is if you use since/until it uses the Committer date, not the Author date.
This discrepancy can be a bit confusing, or lead to unexpected results.
eg: git log --since="yesterday"

--date
You can commit or amend, setting the Author date to any date:

git commit --date="Wed Apr 15 13:00 2037 -0700"
git commit --amend --date="Wed Apr 15 13:00 2037 -0700"

But, you have to use fixed dates, in a format such as ISO 8601, or Internet Message RFC 2822 Format. YYYY.MM.DD, MM/DD/YYYY, DD.MM.YYYY will all work, but I believe a time must also be included.

source has additional options: https://alexpeattie.com/blog/working-with-dates-in-git

This SO post shows a method to set Commit and Author dates, independently, to specific dates, and on multiple commits. Though it is recommended to not change Commit dates on anything that other people use.


Instead of git rebase -i b4465be, copy the recent log into the clipboard and do:

git reset --soft b4465be
git commit

paste and edit the change logs, save & exit from the commit message editor.

Tags:

Git

Git Rebase