error: Your local changes to the following files would be overwritten by merge

简介: error: Your local changes to the following files would be overwritten by merge

拉取代码出现 error: Your local changes to the following files would be overwritten by merge 解决方案

你团队其他成员修改了某文件并已提交入库。
你在pull之前修改了本地该文件,等你修改完代码再pull时,这时会报错如下错误:
error: Your local changes to the following files would be overwritten by merge

解决办法1 --保留修改的代码

执行以下三条命令
git stash #封存修改
git pull origin master 
git stash pop #把修改还原
这三行代码是先封存我们本地的修改。
然后拉取远端代码
最后将我们封存的代码恢复原状。
然后在执行 git add . --> pull -->commit --> push
在我们执行 pull 时候注意是否有冲突

注释

git stash:备份当前工作区内容,从最近的一次提交中读取相关内容,让工作区保证和上次提交的内容一致。
  同时,将当前工作区内容保存到Git栈中
          $ git stash
执行后会出现:Saved working directory and index state WIP on  xxx
git pull:拉取服务器上当前分支代码
git stash pop:从Git栈中读取最近一次保存的内容,恢复工作区相关内容。
同时,用户可能进行多次stash操作,需要保证后stash的最先被取到,
所以用栈(先进后出)来管理;pop取栈顶的内容并恢复
执行后会出现
Auto-merging xxxxxx
CONFLICT (content): Merge conflict in yyyyyy
The stash entry is kept in case you need it again.
git stash list:显示Git栈内的所有备份,可以利用这个列表来决定从那个地方恢复。
git stash clear:清空Git栈

方法2:遗弃当前的修改

核心思想就是版本回退,具体命令如下
git reset --hard 
git pull origin master
注:不建议使用第二种。除非你再三确定不需要本地的修改了。

遇见问题,这是你成长的机会,如果你能够解决,这就是收获。

相关文章
|
缓存 JavaScript
Error: EPERM: operation not permitted, mkdir ‘C:\Program Files\nodejs‘TypeError: Cannot read proper
Error: EPERM: operation not permitted, mkdir ‘C:\Program Files\nodejs‘TypeError: Cannot read proper
157 0
|
7月前
|
存储 开发工具 git
【SourceTree】Your local changes to the following files would be overwritten by merge【解决办法】
【SourceTree】Your local changes to the following files would be overwritten by merge【解决办法】
Error: Plugin/Preset files are not allowed to export objects, only functions……
Error: Plugin/Preset files are not allowed to export objects, only functions……
|
开发工具 git
git更新:Your local changes to the following files would be overwritten by merge
git更新:Your local changes to the following files would be overwritten by merge
272 0
Manifest merger failed with multiple errors, see logs
Manifest merger failed with multiple errors, see logs
129 0
|
Java 开发工具 Maven
git解决error: The following untracked working tree files would be overwritten by c
git解决error: The following untracked working tree files would be overwritten by c
1699 0
解决 lupdate warning: no TS files specified.
解决 lupdate warning: no TS files specified.
LD_LIBRARY_PATH shouldn't contain the current directory when building glibc. Please change the envir
执行# ./glibc-2.14/configure 出现以下错误: checking LD_LIBRARY_PATH variable... contains current directory configure: error: *** LD_LIBRARY_PATH ...
1944 0