views:

40

answers:

1

Hi, I just committed the wrong source to my project using -FORCE.

Is it possible to revert? I understand that all previous branches have been overwritten using -f, so I may have screwed up my previous revisions... I'm a bit of a newbie with GIT.

+1  A: 

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 --force. 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 --force unless you really, really mean it.

Cameron Skinner
yea... unfortunately I've actually gone 1 step further and lost the .git directory which would be able to give me the SHA1's for lost-found commits... thus I'm going to need to wait and get someone who has a full pull of the latest source to recommit. That or I have to do a disk recovery.
David van Dugteren
You can very likely just look at the reflogs to determine where the remote branches originally were. For example, `git reflog show remotes/origin/master`. You should be able to see your push in there; the commit in the previous line is where it was before you messed it up. You can then just push that revision (with `--force`) to origin, and be back where you were!
Jefromi
I blame Bash for confusing me as to which directory... thought I was rm -fR * 'ing
David van Dugteren
@David: Oh. You didn't mention in your question that you didn't have the repo. (This is of course something you never want to do.) If you have filesystem access where you pushed to, though, you could still do all of this there.
Jefromi
@David: Yikes. Always good to have your current directory as part of your prompt to avoid that sort of thing.
Jefromi
Yea... not feeling too proud of that one, I have to wait until someone comes online with the source. The odds of losing a local and remote copy simultaneously were low, and yet I achieved it.
David van Dugteren