40

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
  • 527
  • 2
  • 15
EpicDavi
  • 6,732
  • 3
  • 19
  • 20
  • 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

4 Answers4

66

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,262,500
  • 529
  • 4,410
  • 5,250
  • 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
  • If I wanted to delete these commits how would I do it? I played a bit and made a mistake a commit in year 2015. – Ender Dec 15 '22 at 09:31
  • @Ender Instead of deleting commits, you can amend them and then force push. But if you need to delete/remove them, [an interactive rebase with a drop command](https://www.youtube.com/watch?v=CsHS2Ah5T-k) is enough (and then force push). – VonC Dec 15 '22 at 09:35
  • @VonC Yeah that video was very useful manage to do what I wanted. Thanks – Ender Dec 15 '22 at 10:18
32
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
  • 6,644
  • 4
  • 36
  • 26
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 !

  • 1
    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
0

You can simply accomplish this If you use tool like TortoiseGit Because, It allows you to do all your stuffs without being worried about commands because all the commands will be taken care for you

All you have to do is dealing with your context menu by right-clicking while you are inside your project folder

The image you will see during commit stage before pushing it to your remote repo

This is last step after it is successfully pushed remotely:

Happy Coding!

Gadrawin
  • 87
  • 1
  • 7