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
注:不建议使用第二种。除非你再三确定不需要本地的修改了。

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

相关文章
|
25天前
|
存储 开发工具 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【解决办法】
|
5月前
|
缓存 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
54 0
|
4月前
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
242 0
Manifest merger failed with multiple errors, see logs
Manifest merger failed with multiple errors, see logs
91 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
1320 0
解决 lupdate warning: no TS files specified.
解决 lupdate warning: no TS files specified.
|
开发工具 git
报错解决:your local changes to the following files would be overwritten by merge: .idea/workspa
报错解决:your local changes to the following files would be overwritten by merge: .idea/workspa
361 0
报错解决:your local changes to the following files would be overwritten by merge: .idea/workspa