当前位置:   article > 正文

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

repo error: your local changes to the following files would be overwritten b

在项目里我们一般都会把自己第一次提交的配置文件忽略本地跟踪

1
[Sun@webserver2 demo]$ git update-index --assume-unchanged <filename>

但是项目里的其他人如果不小心把该配置文件修改push到远程仓库之后,我们git pull代码的时候就会报错

1
2
3
4
5
6
7
8
9
10
11
12
13
[Sun@webserver2 demo]$ git add .
[Sun@webserver2 demo]$ git commit -m  'update:index.php'
[master f8a7428] update:index.php
  file changed, 1 insertion(+), 1 deletion(-)
[Sun@webserver2 demo]$ git pull
remote: Counting objects: 5,  done .
remote: Compressing objects: 100% (2 /2 ),  done .
remote: Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3 /3 ),  done .
From git.oschina.net:sunzmit /thinkphp
    1bc9485..c63dff3  master     -> origin /master
error: Your  local changes to the following files would be overwritten by merge:
     config.ini

大意是:您的本地更改的文件将被合并覆盖。并指出了会被覆盖的文件

解决方法:

1.撤销本地对文件的忽略

1
[Sun@webserver2 demo]$ git update-index --no-assume-unchanged config.ini

2.从最近的一次提交中读取内容,备份当前的工作区的内容,将当前的工作区内容保存到Git栈中

1
2
3
[Sun@webserver2 demo]$ git stash
Saved working directory and index state WIP on master: f8a7428 update:index.php
HEAD is now at f8a7428 update:index.php

3.pull远程仓库代码

1
2
3
4
[Sun@webserver2 demo]$ git pull
Merge made by the  'recursive' strategy.
  config.ini | 2 +-
  file changed, 1 insertion(+), 1 deletion(-)

4.从Git栈中读取最近一次保存的内容,恢复工作区的相关内容

1
2
3
[Sun@webserver2 demo]$ git stash pop
Auto-merging config.ini
CONFLICT (content): Merge conflict  in config.ini

5.修改合并

1
2
3
4
5
6
7
8
[Sun@webserver2 demo]$ vim config.ini
<<<<<<< Updated upstream
This is a  test file !!!!!!!!!!!!!!!!
=======
This is a  test file
>>>>>>> Stashed changes
[Sun@webserver2 demo]$  cat test .txt
This is a  test file

<<<<<<< Updated upstream到=======中是从远程仓库pull下来别人的内容,=======到>>>>>>> Stashed changes中是我们本地文件内容,现在我们可以删除其他,只保留自己的内容This is a test file

6.把文件回复到最新提交的版本,会保留修改内容

1
2
3
4
5
[Sun@webserver2 demo]$ git reset HEAD config.ini
Unstaged changes after reset:
M config.ini
[Sun@webserver2 demo]$  cat test .txt
This is a  test file

7.再次忽略本地跟踪,完成!

1
[Sun@webserver2 demo]$ git update-index --assume-unchanged config.ini

8.最后不要忘记清除Git栈的备份

1
[Sun@webserver2 demo]$ git stash drop

本文永久地址:http://blog.it985.com/10665.html
本文出自 IT985博客 ,转载时请注明出处及相应链接。

转载于:https://www.cnblogs.com/yw0219/p/6020878.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/608525
推荐阅读
相关标签
  

闽ICP备14008679号