If you want to rebase-edit the commit message in an old commit, and keep the original commit date, you can do that using the --committer-date-is-author-date
flag. Here's how:
- Find your old commit that you want to edit and copy its hash
- Run
git rebase -i hash^
- Find your commit in the list that shows up and type
edit
in front of it - Run
git commit --amend
to enter editing mode for that commit, make your changes - Type
git rebase --continue
to put the commit back into the history. At this point you will have all of the dates from your commit going forward rewritten to now - This. Run
git rebase --committer-date-is-author-date olderhash
, where olderhash is the hash of the commit just before the edited one which acts as a reference. All commits from the olderhash, starting with the just edited one, will have the dates restored to the corresponding authoring dates.
The good news is this allows restoring the dates even after the rebase had been completed and all the dates seem to have been lost or overwritten.
Sources: