Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one change the timestamp of an old commit in Git?

The answers to How to modify existing, unpushed commits? describe a way to amend previous commit messages that haven't yet been pushed upstream. The new messages inherit the timestamps of the original commits. This seems logical, but is there a way to also re-set the times?

like image 333
Dhskjlkakdh Avatar asked Jan 18 '09 06:01

Dhskjlkakdh


People also ask

How do I change a previous commit in git?

There are many ways to rewrite history with git. Use git commit --amend to change your latest log message. Use git commit --amend to make modifications to the most recent commit. Use git rebase to combine commits and modify history of a branch.

Can I backdate a git commit?

If you want to commit to a even older date, say 3 days back, just change the date argument: date -v-3d . That's really useful when you forget to commit something yesterday, for instance. Show activity on this post. In my case, while using the --date option, my git process crashed.

How do I change a previous commit to a change?

To just edit a commit message (without adding new changes to your last commit), just run the amend command without adding changes. Simple as that!


1 Answers

You can do an interactive rebase and choose edit for the commit whose date you would like to alter. When the rebase process stops for amending the commit you type in for instance:

git commit --amend --date="Wed Feb 16 14:00 2011 +0100" --no-edit 

P.S. --date=now will use the current time.

Afterward, you continue your interactive rebase.

To change the commit date instead of the author date:

GIT_COMMITTER_DATE="Wed Feb 16 14:00 2011 +0100" git commit --amend --no-edit 

The lines above set an environment variable GIT_COMMITTER_DATE which is used in amending commit.

Everything is tested in Git Bash.

like image 180
Paul Pladijs Avatar answered Oct 06 '22 10:10

Paul Pladijs