1.1准备新的feature1
分支,继续我们的新分支开发:
$ git checkout -b feature1
Switched to a new branch 'feature1'
1.2修改readme.txt最后一行,改为:
Creating a new branch is quick AND simple.
1.3在feature1
分支上提交:
$ git add readme.txt
$ git commit -m "AND simple"
[feature1 75a857c] AND simple
1 file changed, 1 insertion(+), 1 deletion(-)
1.4切换到master
分支:
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
1.5在master分支上把readme.txt文件的最后一行改为:
Creating a new branch is quick & simple.
1.5提交:
$ git add readme.txt
$ git commit -m "& simple"
[master 400b400] & simple
1 file changed, 1 insertion(+), 1 deletion(-)
1.6现在,master分支和feature1分支各自都分别有新的提交,变成了这样:
0.png
1.6这种情况下,Git无法执行“快速合并”,只能试图把各自的修改合并起来,但这种合并就可能会有冲突
$ git merge feature1
Auto-merging readme.txt
CONFLICT (content): Merge conflict in readme.txt
Automatic merge failed; fix conflicts and then commit the result.
image.png
1.7Git用<<<<<<<
,=======
,>>>>>>>
标记出不同分支的内容,我们修改如下后保存:
Creating a new branch is quick and simple.
1.8现在,master分支和feature1分支变成了下图所示:
1.png
1.9用带参数的git log --graph
可以看到分支的合并情况:
$ git log --graph --pretty=oneline --abbrev-commit
* 59bc1cb conflict fixed
|\
| * 75a857c AND simple
* | 400b400 & simple
|/
* fec145a branch test
...
image.png
2.0最后,删除feature1分支:
$ git branch -d feature1
Deleted branch feature1 (was 75a857c).
网友评论