This branch has conflicts that must be resolved 解决示例

使用git日常免不了遇到conflicts,那么如何消除conflicts呢,以下的内容以一个具体的过程来讲解整个过程和原理。

以下我们手动创造一个conflicts:
git conflicts

Step 1: From your project repository, check out a new branch and test the changes.

git checkout -b apache-master master
git pull https://github.com/apache/incubator-apisix.git master

Step 2: Merge the changes and update on GitHub.

git checkout master
git merge --no-ff apache-master
git push origin master

以上的的例子, 我们从A合入到B:B <== A。
A: https://github.com/apache/incubator-apisix.git
B: xxxx/incubator-apisix.git

例子中有一个README.md的冲突,并且给出了解决的命令行参考。
我们将逐条命令来解释如何按照提示解决冲突。

  1. 假设我们已经在B的git 根目录下。
  2. git checkout -b apache-master master #建立B的 apache-master分支,并切换到apache-master
  3. git pull https://github.com/apache/incubator-apisix.git master # 将A最新的内容合入apache-master
  4. 因为有冲突,所以上条执行时,会提示冲突:
    From https://github.com/apache/incubator-apisix
    * branch            master     -> FETCH_HEAD
    Auto-merging README.md
    CONFLICT (content): Merge conflict in README.md
    Automatic merge failed; fix conflicts and then commit the result.
  5. 解决冲突[ ... resolve any conflicts ... ]:
    手动打开冲突文件,根据提示修改,删除冲突的内容,留下想要的结果内容。
  6. git add [files that were conflicted]
  7. git commit,将冲突修改提交敖本地仓库:
    $ git commit -m "resolve the conflict"
    [apache-master 6ad2d5e] resolve the conflict
  8. git checkout master # 将B切换为master
  9. git merge --no-ff apache-master #将B仓库的apache-master 合入 master
  10. git push origin master #将B仓库的最终的本地库推到云端master

最终解决了冲突,完成了对B master的更新。

希望以上就解释清楚,谢谢!

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注