Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I recover from an erronous git push -f origin master?

I just committed the wrong source to my project using --force option.

Is it possible to revert? I understand that all previous branches have been overwritten using -f option, so I may have screwed up my previous revisions.

like image 798
David van Dugteren Avatar asked Oct 20 '10 00:10

David van Dugteren


People also ask

What happens after git push origin master?

Git Push Origin pushes all the branches to the main branch. Git Push Origin Master pushes your master branch to the origin. Behavior could be changed via git config. Behaviour is by default.


1 Answers

Git generally doesn't throw anything away, but recovering from this may still be tricky.

If you have the correct source then you could just push it into the remote with the --force option. Git won't have deleted any branches unless you told it to. If you have actually lost commits then take a look at this useful guide to recovering commits. If you know the SHA-1 of the commits you want then you're probably OK.

Best thing to do: Back everything up and see what is still in your local repository. Do the same on the remote if possible. Use git fsck to see if you can recover things, and above all DO NOT run git gc.

Above above all, never use the --force option unless you really, really mean it.

like image 176
Cameron Skinner Avatar answered Sep 21 '22 21:09

Cameron Skinner