I just did something dumb. In my fooclient project, I just did:
git remote add official https://github.com/fooserver
git pull official master
In other words, I pulled a completely different codebase (the server, instead of the client) into my working directory. Not surprisingly, there weren’t many merge conflicts (the file names are all completely different, after all). Also not surprisingly, Git completely failed to warn me that the repos didn’t have a single common ancestor.
In this particular situation, I’m able to recover by doing this:
cp file-i-worked-on.js ~
git reset --hard HEAD # to discard broken merge conflicts
git checkout a12345 # where a12345 is the latest head of fooclient that I had checked out
cp ~/file-i-worked-on.js .
But what would be the more general strategy?
This will reset you to the last state master was in:
This is possible because of the reflog. Running
git reflogwill show you the reflog, and allow you to verify you’re resetting to the correct state.