冲突产生
在下面的条件均满足的情况下会造成冲突:
- 两个不同的分支对项目的同一个文件中的同一行有不同的修改
- 试图合并两个分支
解决冲突
合并分支时会有提示:
$ git merge feature1 Auto-merging readme.txt CONFLICT (content): Merge conflict in readme.txt Automatic merge failed; fix conflicts and then commit the result.可以通过 git status 查看具体的冲突位置
$ git status # On branch master # Your branch is ahead of 'origin/master' by 2 commits. # # Unmerged paths: # (use "git add/rm <file>..." as appropriate to mark resolution) # # both modified: readme.txt # no changes added to commit (use "git add" and/or "git commit -a")冲突标记
- Git用
<<<<<<<,=======,>>>>>>>标记出不同分支的内容 - 选出真正想保留的那一本分
- 去掉上面的标记
- 重新提交
- Git用