git-shift: Changing commit timestamps in Git

Git is known to be so flexible that one can even fix or delete old commits, but what would you do if you wanted to change the timestamp of a particular commit? This need can arise for various reasons, such as when a merged commit has picked the unwanted timestamp on squash, when a contributor’s (or your notebook’s) machine clock was obviously far out of sync, and so on.
git-shift (update: repository moved) is the tool I wrote to change dates (timestamps) of specified commits in a git repository.  The choice of the name sounds a bit too bold, so maybe I will rename it later—but anyway.
The usage is simple; specify the amount of time you want to shift timestamps by, and a list of commit IDs you want to change timestamps of. (Range notation is currently not supported)
e.g. to move timestamps of commits identified by the IDs f9e8d7c6 and 579acf two hours backwards:

$ git-shift -2h f9e8d7c6 579acf

Use it wisely and enjoy your life, night and day workers! :D

7 thoughts on “git-shift: Changing commit timestamps in Git

  1. 武者さん、OS Xで使おうとすると、「line 86: `git-shift’: not a valid identifier」のメーサッジがあります。解決は知りますか?

  2. ああ、解いたと思います。問題は「git-shift」がshでだめの機能名前だと思います。「git-shift」を「git_shift」に変更すれば、作動します。

  3. Great work! You saved my life.
    But i have a question.
    Is there a way to reverse date changes and get back original commit date.

    Thanks.

    • `git reflog` is your friend. Use `git log –pretty-fuller commitID` to check if the commitID is where you want to go back, and if so, run `git reset –hard commitID` to get back.

Leave a Reply

Your email address will not be published.