StarkerSong Get Busy Living

git pull错误解决办法

2016-09-18

晚上在台式机和笔记本上同时更新编写博客文档,在笔记本的linux环境下主要编写程序代码,在台式机上上传图片,但是在台式机git shell中并入服务器内容至本地时出现下面的错误:

C:\Users\song\StarkerSong.github.io [master +0 ~1 -0]> git pull
Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of know
n hosts.
Updating cbdfda7..c670a5a
error: Your local changes to the following files would be overwritten by merge:
        _posts/2016-09-18-linux-c++-g++.md
Please, commit your changes or stash them before you can merge.
Aborting

主要就两个步骤:

  • 通过执行git reset --hard,把版本库、暂存区和工作区都回退到HEAD的前一个版本。
  • 使用git pull将本地内容更新为远程分支。(注:在使用时尽量使用git fetchgit merge
C:\Users\song\StarkerSong.github.io [master +0 ~1 -0]> git reset --hard
HEAD is now at cbdfda7 update
C:\Users\song\StarkerSong.github.io [master]> git pull
Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of know
n hosts.
Updating cbdfda7..c670a5a
Fast-forward
 _posts/2016-09-18-linux-c++-g++.md | 91 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 90 insertions(+), 1 deletion(-)

上面是更新本地内容,如果希望保留生产服务器上所做的改动,仅仅并入新配置项, 处理方法如下:

git stash
git pull
git stash pop

然后可以使用git diff -w +文件名 来确认代码自动合并的情况.

参考资料


Comments