Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update git commit author date when amending

Tags:

git

I found myself amending my commits quite often. I don't stash so much because I tend to forget I did so, especially when I want to save what I did before I leave or before a weekend, so I do a "draft" commit. Only thing is, when I amend the commit, it is still set to the original author date. Is there a (simple) way to update it when amending?

like image 250
ksol Avatar asked Feb 02 '12 09:02

ksol


People also ask

Does amend Change commit date?

Just do git commit --amend --reset-author --no-edit . For older commits, you can do an interactive rebase and choose edit for the commit whose date you want to modify.

How do I update an existing commit?

You can modify the most recent commit in the same branch by running git commit --amend. This command is convenient for adding new or updated files to the previous commit. It is also a simple way to edit or add comments to the previous commit. Use git commit --amend to modify the most recent commit.

Does amend Change commit ID?

commit message Show activity on this post. Amending a Git commit changes the commit date (which is different from the date you initially see when running git log -- run git log --format=fuller to see the commit date). The commit date is taken into account when creating the commit hash.


2 Answers

You can change the author date with the --date parameter to git commit. So, if you want to amend the last commit, and update its author date to the current date and time, you can do:

git commit --amend --date="$(date -R)" 

(The -R parameter to date tells it to output the date in RFC 2822 format. This is one of the date formats understood by git commit.)

like image 156
Mark Longair Avatar answered Sep 24 '22 14:09

Mark Longair


As of Git v2.1.4 (tested on Debian 8 (Jessie))

git commit --amend --date=now 
like image 32
Kamal Avatar answered Sep 24 '22 14:09

Kamal