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?
Asked
Active
Viewed 8,200 times
14
-
Don't think it is possible. Look at https://docs.gitlab.com/ee/api/commits.html . The `committed_date` is probably to be set by github only. – jschnasse Nov 02 '20 at 14:25
-
Technically, you cannot change *anything* about any *existing* commit. What you can do is make a new (different) commit that's almost exactly the same as the existing commit, but has whatever it is that you want to be different, different. That's what `git commit --amend` does, but note that `00/00/0000` isn't possible as it's not a valid date. `2000-01-01` (note the `01`s) is a valid date. – torek Nov 02 '20 at 14:58
-
1Once you've made a new commit, you'll have to convince that other Git on GitHub to stop using the old commit and start using the new one. That generally requires `git push --force` or `git push --force-with-lease`. – torek Nov 02 '20 at 14:59
-
Does this answer your question? [How can one change the timestamp of an old commit in Git?](https://stackoverflow.com/questions/454734/how-can-one-change-the-timestamp-of-an-old-commit-in-git) – creativecreatorormaybenot Oct 04 '21 at 23:02
2 Answers
32
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"

Jackkobec
- 5,889
- 34
- 34
-
2Thanks .This does not change the date in my github repo profile.It does change the date of the commit in my local repo.I am looking for a way to have the change show up once I push the code upstream. – Aliman Nov 02 '20 at 14:07
-
1This does *not* change the date of the last commit. It creates a new commit that has the same underlying tree. – William Pursell Sep 04 '21 at 12:10
-
7
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)

Hrishikesh
- 1,076
- 1
- 8
- 22