27

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.

dreua
  • 529
  • 2
  • 15
EpicDavi
  • 5,482
  • 3
  • 18
  • 19
  • duplicate: http://stackoverflow.com/questions/3895453/how-do-i-make-a-git-commit-in-the-past – ctor May 12 '14 at 13:16
  • @ctor That question does not specify the GitHub result... would it work in the same way? – EpicDavi May 12 '14 at 13:26
  • 1
    @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. – sleske May 12 '14 at 13:41
  • @sleske What is the easier way to do this? – EpicDavi May 12 '14 at 14:01

3 Answers3

53

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.

Jetroid
  • 25
  • 7
VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
  • sleske 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 May 12 '14 at 14:03
  • Do I commit first and then run this command, or does this command commit for me? – EpicDavi May 12 '14 at 16:22
  • 1
    @EpicDavi no this command is meant to fix the last commit you did. So commit first, then amend the date. – VonC May 12 '14 at 17:06
  • To 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. – James Skemp Nov 07 '15 at 22:27
  • @JamesSkemp Thank you. I have included the command in the answer for more visibility. – VonC Nov 07 '15 at 22:53
  • 1
    Ya, that's work for me! Doesn't break my commit streak on github. Thanks. – akshay_sushir May 28 '21 at 05:17
  • @akshay_sushir Great, glad it is still helpful after all those years. Note: your Stack Overflow profile (https://stackoverflow.com/users/11873929/akshay-sushir) reference your GitHub profile as https://github.com/akshaysushir instead of https://github.com/axaysushir. – VonC May 28 '21 at 06:54
  • 1
    @VonC Oh, I forgot to change my GitHub Profile, thanks. I Changed it. – akshay_sushir May 30 '21 at 06:01
27
git commit --allow-empty --date="Sat Nov 14 14:00 2015 +0100" -m '2 Dec commit'

It will create empty commit with provided date

Yash
  • 5,814
  • 2
  • 34
  • 25
1

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 !

  • The 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! – Diyorbek Sadullaev May 20 '22 at 01:17