Ant's Ant's - 1 year ago 128
Git Question

How to recover from git push -f?

I have done a

git push -f
on a branch and now lost the other persons work.

I could able to see in my github that the other person work is shown (shown in activity), but not in the remote branch (where I pushed my changes). Unfortunately I don't have my local repo sync up with remote. So I don't have other persons code in my local. Is there a way I can get that to my local and recover?

Answer Source

Before doing anything else, please do these 3 steps - backup your local repo, tell the other guy to backup his, and backup the remote repo as they are now. Nothing fancy, just Ctrl+C, Ctrl+V would do. Do it on your entire project so you backup the working tree as well. If you don't have direct access to the remote server, a git clone would have to suffice, though I would prefer a real directory copy.

Once you've done that, the other guy can use git push -f to reupload his branch. If he has new commits, you will have to figure out which commit was last pushed by him, but I'm fairly sure no actual commits will be lost. If the other guy has done git pull -f, even then he can use git reflog to recover his local branch.

Since you're using Github, you might also see Apparently there is a Github’s Events API which might be useful.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download