Reword a commit message without changing the commit date

in Development


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:

  1. Find your old commit that you want to edit and copy its hash
  2. Run git rebase -i hash^
  3. Find your commit in the list that shows up and type edit in front of it
  4. Run git commit --amend to enter editing mode for that commit, make your changes
  5. 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
  6. 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:

#git