git命令行解决冲突方法

方法一、

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

git checkout [文件路径]
git checkout test/src/main/resources/application.yml
git pull;
IDEA 可以试用revert

方法二、

git pull 出现冲突后可以暂存本地修改git stash save "savemessage",然后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:application.yml
Please commit your changes or stash them before you merge.

​ 这说明你的application.yml与远程有冲突,你需要先提交本地的修改然后更新。

  1. git add application.yml,然后使用 git commit -m '冲突解决'

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

  2. git pull,更新代码会出现以下错误提示

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

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

  3. 找到你本地的application.yml文件,并打开

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

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

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

  1. 重新使用git add application.yml,然后git commit -m '冲突解决结束',再次将本地的application.yml文件提交

  2. 解决冲突后,使用git push,将文件推送到远程

posted @ 2020-05-06 21:11  山那边风景  阅读(17171)  评论(0编辑  收藏  举报