刚刚写完代码 git push 提交时,仓库改动,所以我在 git pull,但是在pull后打印了错误信息
spider-man@ubuntu:~/APUE-study/LuXiaoyang$ git pull
D LHJ/.keep
A LeiHaoJie/.keep
A LeiHaoJie/hello.c
A LeiHaoJie/socket_server_thread.c
U LuXiaoyang/ch1/connet_by_hostname.c
A LuXiaoyang/ch1/my.c
A Wangruijie/daemon.c
A Wangruijie/socket_server_thread.c
A ZYN/socket_server.c
A ZhangYinan/database_module_test.c
A ZhangYinan/db_in.c
A ZhangYinan/shared_mem_write.c
A chenxiaohong/ch3/fork.c
A chenxiaohong/ch3/fork_exec.c
A chenxiaohong/ch3/fork_var.c
A chenxiaohong/ch3/popen.c
A chenxiaohong/ch3/socket_server.c
A chenxiaohong/ch4/.keep
A xuxinhua/apue/select.c
A xuxinhua/wenduchuangan/ds18b20.c
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.
原来,在git pull的过程中,如果有冲突,那么除了冲突的文件之外,其它的文件都会做为staged区的文件保存起来。
本地的push和merge会形成MERGE-HEAD(FETCH-HEAD), HEAD(PUSH-HEAD)这样的引用。HEAD代表本地最近成功push后形成的引用。MERGE-HEAD表示成功pull后形成的引用。
解决方法
将本地的冲突文件冲掉,不仅需要reset到MERGE-HEAD或者HEAD,还需要–hard。没有后面的hard,不会冲掉本地工作区。只会冲掉stage区。注意,使用第一个命令时,要先将本地刚写的代码copy一份,再执行命令;
git reset --hard FETCH_HEAD
git pull就会成功。