Git (GitHub) commit at past date
Solution 1
While the question "How do I make a Git commit in the past?" explains how to amend the commit author date:
git commit --amend --no-edit --date="Fri Nov 6 20:00:00 2015 -0600"
Run that after a commit to amend the last commit with the timestamp noted.
The--no-edit
will leave the message as-is.
The OP asks:
That question does not specify the GitHub result... would it work in the same way?
Yes: multiple projects exist allowing you to generate and push commits "done in the past", in order to update your contribution chart.
See for instance contribution.io, github-contribution, or gitgardener.
All you need to do, is to push those amended commit on the master
branch of your GitHub repo, as I mention here.
Solution 2
git commit --allow-empty --date="Sat Nov 14 14:00 2015 +0100" -m '2 Dec commit'
It will create empty commit with provided date
Solution 3
Works only when the system date is reverted to yesterday by changing the Time Zone
and no commits are made on the current day already.
- Open
Date & Time
Settings -
Set time zone automatically
- Turn it off - Using the
Time Zone
dropdown select a time zone that changes the system date to yesterday. - Now open github and commit. Check the contributions graph.
-
Set time zone automatically
- Turn it on.
The above method worked out for me. Cheers !
Related videos on Youtube
Comments
-
EpicDavi about 3 years
I am working on a git project (hosted on GitHub) and using GitHub for Windows. Yesterday, I got a lot accomplished but GitHub for Windows bailed on me (says it cannot make a commit) and I was not able to commit.
I do not want to lose my GitHub commit streak, so I was wondering if there was any way to commit in a past date and sync with my GitHub (if this is possible).
Also: I have staged my commits in the git-bash but have not committed yet.
-
ctor about 10 yearsduplicate: stackoverflow.com/questions/3895453/…
-
EpicDavi about 10 years@ctor That question does not specify the GitHub result... would it work in the same way?
-
sleske about 10 years@EpicDavi: Yes, GitHub mostly works like any other remote git repo. However, the question is about backdating a commit to go before other commits, which is more complicated than just backdating the next commit.
-
EpicDavi about 10 years@sleske What is the easier way to do this?
-
-
EpicDavi about 10 yearssleske had commented that the linked question is explaining backdating a commit before other commits. Do you know any easier way to backdate my latest to-be commit? (latest code)
-
EpicDavi about 10 yearsDo I commit first and then run this command, or does this command commit for me?
-
VonC about 10 years@EpicDavi no this command is meant to fix the last commit you did. So commit first, then amend the date.
-
James Skemp over 8 yearsTo save someone from digging through that post:
git commit --amend --no-edit --date="Fri Nov 6 20:00:00 2015 -0600"
Run that after a commit to amend the last commit with the timestamp noted. The--no-edit
will leave the message as-is. -
VonC over 8 years@JamesSkemp Thank you. I have included the command in the answer for more visibility.
-
Yash almost 7 years@std''OrgnlDave why do you think answer is incomplete?
-
anion about 5 yearsthis only sets the "date". the "commit-date" of the commit is still the current time of the system-clock
-
Upulie Han almost 4 yearsdon't you have to use double quotes for the commit message?
-
Yash almost 4 yearsTerminal don't care single or double. Mostly.
-
akshay_sushir almost 3 yearsYa, that's work for me! Doesn't break my commit streak on github. Thanks.
-
VonC almost 3 years@akshay_sushir Great, glad it is still helpful after all those years. Note: your Stack Overflow profile (stackoverflow.com/users/11873929/akshay-sushir) reference your GitHub profile as github.com/akshaysushir instead of github.com/axaysushir.
-
akshay_sushir almost 3 years@VonC Oh, I forgot to change my GitHub Profile, thanks. I Changed it.
-
bilalmohib almost 3 yearsWow @Yash I am so happy that works unexpectedly.Amazing Answer sir.Thank you.
-
Diyorbek Sadullaev almost 2 yearsThe exact solution I've been looking for! Works like a charm! The other solutions were just changing the commit date in git but not on GitHub. Thank you!