Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is possible change the commit date on git? [duplicate]

Tags:

git

When I commited my work, the pc date was 02/13/2014, but the correct date was 01/13/2014. Is possible the change commit date to the correct date?

like image 838
ewerton Avatar asked Jan 14 '14 11:01

ewerton


People also ask

Can you change git commit date?

For all commits where you want to change the date, replace pick by edit (or just e ), then save and quit your editor. The first date is the commit date, the second one is the author date. Repeat the process until you amend all your commits. Check your progression with git status .

How do I overwrite a previous commit?

If you've already created a fresh commit, you'll want to use git rebase -i to squash your commit on top of the old one. After you've made this change locally, and verified your commit looks the way you want it to, you'll have to git push --force to overwrite history on the Github remote.


1 Answers

If it is your latest commit:

git commit --amend --date="Wed Jan 13 12:00 2014 +0100"

If it is for example your 5th last commit, you can do an interactive rebase and edit the commit:

git rebase -i HEAD~5
<find the commit and change 'pick' to 'e', save and close file>
git commit --amend --date="Wed Jan 13 12:00 2014 +0100"
git rebase --continue

Keep in mind that this rewrites history.

like image 87
Agis Avatar answered Oct 26 '22 13:10

Agis