我刚刚做了一件傻事。在我的fooclient项目中,我做了以下操作:
git remote add official https://github.com/fooserver
git pull official master
换句话说,我将一个完全不同的代码库(服务器而非客户端)拉入我的工作目录。毫不奇怪,几乎没有合并冲突(毕竟文件名完全不同)。同样不足为奇的是,Git完全没有警告我这些仓库没有共同的祖先。
在这种特殊情况下,我可以通过以下方式恢复:
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 .
但是更一般的策略会是什么呢?