Git – Set the Author Date to The Committer Date of a Recent Commit

hakre-git-committer-date-git-gone-1

Ah gosh that one commit has the author date just too far off, but if it
would be the same as the committer date, that would be fine…

  1. Locate the commit when rebase interactively and mark for edit. Then
    go there to edit [1].
  2. Extract and export that commits committer date as GIT_COMMITTER_DATE
    $ export GIT_COMMITTER_DATE="$(git log --format=%cD -1)"
  3. Amend w/ the author date then set to the committer date while preserving it via the exported environment parameter (variable)
    $ git commit --amend --date="$GIT_COMMITTER_DATE" -C HEAD
  4. Unset the GIT_COMMITTER_DATE
    $ unset GIT_COMMITTER_DATE
  5. Continue the rebase to finish
    $ git rebase --continue

An update to this post with one-liners and a couple of more options is available:


hakre-git-committer-date-git-gone-2

[1] A date/time related intro to interactive rebase is also given in Change the date of a git commit (by Hugo Di Francesco; Aug 2018), the whole story in the git manual on interactive rebase which is always worth the read.

Images motive based on a visual excerpt from a TV series episode named “git gone” which is also the imaginary product name, the further text reads “kills bugs on contact” on the spray can label.

This entry was posted in Hakre's Tips, Pressed and tagged . Bookmark the permalink.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.