Your local changes to the following files would be overwritten by merge: ... Please, commit your cha

Git出现error: Your local changes to the following files would be overwritten by merge: ... Please, commit your changes or stash them before you can merge.的问题解决(Git代码冲突)git

 

在使用git pull拉取服务器最新版本时,若是出现error: Your local changes to the following files would be overwritten by merge: ... Please, commit your changes or stash them before you can merge.错误时,表明这代码冲突了,本地修改了代码致使没法覆盖服务器上的。服务器

此时有以下解决方法:post

注意:在作全部操做前,切记要先备份本地代码。.net

一、若是但愿保留生产服务器上所作的改动,仅仅并入新配置项, 处理方法以下:code

git stash
git pull
git stash pop

而后可使用Git diff -w +文件名来确认代码自动合并的状况。blog

二、若是要直接使用服务器上最新版本,那么能够选择直接覆盖it

git reset --hard
git pull

其中git reset是针对版本。ast

 

http://blog.csdn.net/misakaqunianxiatian/article/details/51103734class

 

 

##############################服务器端

方法1:若是你想保留刚才本地修改的代码,并把git服务器上的代码pull到本地(本地刚才修改的代码将会被暂时封存起来)

git stash  
git pull origin master  
git stash pop

 

如此一来,服务器上的代码更新到了本地,并且你本地修改的代码也没有被覆盖,以后使用add,commit,push 命令便可更新本地代码到服务器了。

 

方法二、若是你想彻底地覆盖本地的代码,只保留服务器端代码,则直接回退到上一个版本,再进行pull

git reset --hard
git pull origin master
相关文章
相关标签/搜索