合并有冲突分支
前提:master分支有一个test.txt文件
1.创建新分支newbranch
$ git branch newbranch #创建newbranch分支
$ git checkout newbranch #进入newbranch分支
#以上两步可以直接写为
$ git checkout -b newbranch
2.在newbranch分支上查看test.txt文件
$ ls
test.txt
$ cat test.txt
测试分支
3.在newbranch分支上修改test.txt文件
4.提交newbranch分支上的修改
$ git add .
$ git commit -m "提交newbranch分支上的修改"
5.切回到master分支,对test.txt文件进行修改
$ git checkout master #跳转到master分支
$ ls #查看master分支的文件
test.txt
6.master分支提交修改
$ git add .
$ git commit -m "master分支提交修改"
7.master分支合并newbranch分支
显示两个分支有冲突
$ git merge newbranch #合并分支
Auto-merging test.txt
CONFLICT (add/add): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then commit the result.
8.解决冲突,合并分支
$ cat test.txt #查看冲突文件
测试分支
<<<<<<< HEAD
在master分支上修改test.txt文件
=======
在newbranch分支上修改test.txt文件
>>>>>>> newbranch
9.修改冲突的文件
10.查看冲突文件的状态
$ git status -s
AA test.txt
11.告诉git我已经解决完冲突了
$ git add test.txt
$ git commit -m "解决掉冲突文件,合并分支"