This branch has conflicts that must be resolved 解决示例
使用git日常免不了遇到conflicts,那么如何消除conflicts呢,以下的内容以一个具体的过程来讲解整个过程和原理。
以下我们手动创造一个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的冲突,并且给出了解决的命令行参考。
我们将逐条命令来解释如何按照提示解决冲突。
- 假设我们已经在B的git 根目录下。
- git checkout -b apache-master master #建立B的 apache-master分支,并切换到apache-master
- git pull https://github.com/apache/incubator-apisix.git master # 将A最新的内容合入apache-master
- 因为有冲突,所以上条执行时,会提示冲突:
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.
- 解决冲突[ ... resolve any conflicts ... ]:
手动打开冲突文件,根据提示修改,删除冲突的内容,留下想要的结果内容。 - git add [files that were conflicted]
- git commit,将冲突修改提交敖本地仓库:
$ git commit -m "resolve the conflict" [apache-master 6ad2d5e] resolve the conflict
- git checkout master # 将B切换为master
- git merge --no-ff apache-master #将B仓库的apache-master 合入 master
- git push origin master #将B仓库的最终的本地库推到云端master
最终解决了冲突,完成了对B master的更新。
希望以上就解释清楚,谢谢!