Change the date of a git commit

One of the greatest and worst things with git is that you can rewrite the history. Here’s a sneaky way of abusing that, I can’t think of a legitimate reason to do this.

As with anything, thanks StackOverflow for all the options I can pick from ?.

GIT_COMMITTER_DATE="$(date)" git commit --amend --no-edit --date "$(date)"

GIT_COMMITTER_DATE="Mon 20 Aug 2018 20:19:19 BST" git commit --amend --no-edit --date "Mon 20 Aug 2018 20:19:19 BST"

Rebase to before said commit and stop for amendment:

  1. git rebase <commit-hash>^ -i
  2. Replace pick with e (edit) on the line with that commit (the first one)
  3. quit the editor (ESC followed by :wq in VIM)
  4. Either:
  • GIT_COMMITTER_DATE="$(date)" git commit --amend --no-edit --date "$(date)"
  • GIT_COMMITTER_DATE="Mon 20 Aug 2018 20:19:19 BST" git commit --amend --no-edit --date "Mon 20 Aug 2018 20:19:19 BST"

See here for more information around rebasing and editing in git: Split an existing git commit.

Facebook Comments

More Stuff

How Much Time Should You Invest In Training? An analytical approach to training, discipline, and automation.“Give me six hours to chop down a tree and I will spend the first four sharpening the...
Git Version Control series: What is Git? This is the first in a series of blog posts around Git and a new feature in version 72, Git Version Control.  See the full list of entries in this ser...
9 Ways a Humble Pencil Can Silence Brain Chatter Ever sit down to do something and suddenly your mind is off on a trail like a dog after a bunny? Which would be great if you stayed on that track, b...
Personal Assistant Kino Part 4 — Smart Feed Smart Feed I wanted to automate my pattern that check new articles, put them in Pocket, read carefully and move to favorite category. This is why Smar...
Spread the love

Posted by News Monkey