Last Updated: February 25, 2016
·
4.264K
· joakimbeng

Handling GitHub for Windows crash on commit

Ever got "Commit failed: Failed to create a new commit" in GitHub for Windows, then noticed that your latest unpushed/unsynced commits is gone and that your local branch is behind the remote origin with several commits?

That has happened to me, and my co-workers many times, and we've lost several hours of work, because of it!

Today I found the solution and here it is:

Check what sha1 hash your repo is really on (and copy that hash) with:

cat .git/refs/heads/<your current branch>.lock

Remove the branch lock with:

rm .git/refs/heads/<your current branch>.lock

Then revert to the correct commit with:

git reset <paste the sha1 hash here>

Ta da! Your previously lost commits is now restored and ready to be pushed/synced.

N.B. I think the best way to avoid this problem is to not use GitHub for Windows at all! Because it feels really unstable and makes your repository broken every now and then. But if you do use it, it can be worth while knowing the above.

1 Response
Add your response

Thanks so much! It was very useful :)

over 1 year ago ·