Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I change the date of a git commit

Tags:

git

github

I need to push some code upstream into my repo. However I would like to see if It is possible to set the date of the commit/push to be something other than the current the date.This would mean if someone visited my github page and my desired date for the push was 00/00/00 it would show as 00/00/00 and NOT the current date.Is there anyway to do this?

like image 778
Aliman Avatar asked Sep 12 '25 19:09

Aliman


2 Answers

You can change the date of last commit:

git commit --amend --no-edit --date=now

or input date:

git commit --amend --no-edit --date="2020.11.02 12:00"
like image 72
Jackkobec Avatar answered Sep 14 '25 10:09

Jackkobec


You can use the environment variable GIT_COMMITTER_DATE to update commit date as well.

export GIT_COMMITTER_DATE='Wed Dec 21 11:51:39 IST 2022'
git commit --amend --no-edit --date='Wed Dec 21 11:51:39 IST 2022'
unset GIT_COMMITTER_DATE

To see if your change has taken effect,

git log --pretty=fuller

(of course, you will need to do a force-push, if you have already pushed the commit to upstream)

like image 45
Hrishikesh Avatar answered Sep 14 '25 10:09

Hrishikesh