mmzuo-798

原文https://blog.csdn.net/zwl18210851801/article/details/79106448

亲测有用,解决git冲突的好办法

方法一(推荐使用):

git pull 出现冲突后丢弃本地冲突文件修改,采用远程文件覆盖本地文件

git checkout  [文件路径]
例:git checkout test/src/main/resources/spring-shiro.xml  

方法二:

git pull 出现冲突后可以暂存本地修改git stash ,然后git pull 更新代码,git stash list 可查看暂存记录列表,释放本地暂存 git stash apply stash@{0} ,出现冲突文件,找到并解决,然后可以提交git add . 加入索引库,然后本地提交git commit -m \'注释\' 最后git push到远程

方法三:

1.git pull

更新代码,发现

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

Please commit your changes or stash them before you merge.
这说明你的pom.xml与远程有冲突,你需要先提交本地的修改然后更新。

2.git add pom.xml

  git commit -m \'冲突解决\'

 提交本地的pom.xml文件,不进行推送远程

3.git pull

更新代码

Auto-merging pom.xml
CONFLICT (content): Merge conflict in pom.xml
Automatic merge failed; fix conflicts and then commit the result.

更新后你的本地分支上会出现 (develop|MERGING)类似这种标志

4.找到你本地的pom.xml文件,并打开

你会在文件中发现<<<<<<< HEAD ,=======  ,>>>>>>> ae9a0f6b7e42fda2ce9b14a21a7a03cfc5344d61

这种标记,<<<<<<< HEAD和=======中间的是你自己的代码,  =======  和>>>>>>>中间的是其他人修改的代码

自己确定保留那一部分代码,最后删除<<<<<<< HEAD ,=======  ,>>>>>>>这种标志

5.git add pom.xml

git commit -m \'冲突解决结束\'

再次将本地的pom.xml文件提交

6.git push

将解决冲突后的文件推送到远程

分类:

技术点:

相关文章:

  • 2022-01-14
  • 2021-12-22
  • 2021-04-10
  • 2021-12-06
  • 2022-01-14
  • 2021-05-29
  • 2022-01-09
  • 2022-01-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2021-11-13
  • 2022-03-03
  • 2021-07-30
  • 2022-02-28
相关资源
相似解决方案