Git (GitHub) commit at past date

25,807

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 !

Share:
25,807

Related videos on Youtube

EpicDavi
Author by

EpicDavi

Nothing much...

Updated on March 04, 2021

Comments

  • EpicDavi
    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
      ctor about 10 years
    • EpicDavi
      EpicDavi about 10 years
      @ctor That question does not specify the GitHub result... would it work in the same way?
    • sleske
      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
      EpicDavi about 10 years
      @sleske What is the easier way to do this?
  • EpicDavi
    EpicDavi about 10 years
    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
    EpicDavi about 10 years
    Do I commit first and then run this command, or does this command commit for me?
  • VonC
    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
    James Skemp over 8 years
    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.
  • VonC
    VonC over 8 years
    @JamesSkemp Thank you. I have included the command in the answer for more visibility.
  • Yash
    Yash almost 7 years
    @std''OrgnlDave why do you think answer is incomplete?
  • anion
    anion about 5 years
    this only sets the "date". the "commit-date" of the commit is still the current time of the system-clock
  • Upulie Han
    Upulie Han almost 4 years
    don't you have to use double quotes for the commit message?
  • Yash
    Yash almost 4 years
    Terminal don't care single or double. Mostly.
  • akshay_sushir
    akshay_sushir almost 3 years
    Ya, that's work for me! Doesn't break my commit streak on github. Thanks.
  • VonC
    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
    akshay_sushir almost 3 years
    @VonC Oh, I forgot to change my GitHub Profile, thanks. I Changed it.
  • bilalmohib
    bilalmohib almost 3 years
    Wow @Yash I am so happy that works unexpectedly.Amazing Answer sir.Thank you.
  • Diyorbek Sadullaev
    Diyorbek Sadullaev almost 2 years
    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!