|
[root@git gittest]# git branch
master
* product
[root@git gittest]# echo "product_write" >> file1.txt #在product上给file1新增一行并提交
[root@git gittest]# git add file1.txt
[root@git gittest]# git commit -m "product test"
[product 95d6308]product test
1 files changed, 1 insertions(+), 0deletions(-)
[root@git gittest]# git checkout master
Switched to branch'master'
Your branch isahead of 'origin/master' by 1 commit.
[root@git gittest]# cat file1.txt
my first file
the test something
[root@git gittest]# echo "master_ write" >> file1.txt #在master上也给file1新增一行
[root@git gittest]# git merge product
Updating76d88ad..95d6308
error: Your localchanges to 'file1.txt' would be overwritten by merge. Aborting. #这时候合并就会提示报错了,会让你先提交代码
Please, commityour changes or stash them before you can merge.
[root@git gittest]# cat file1.txt
my first file
the test something
master_ write
[root@git gittest]# git add file1.txt
[root@git gittest]# git commit -m "master test" #master提交
[master f801103]master test
1 files changed, 1 insertions(+), 0deletions(-)
[root@git gittest]# git merge product #提交完之后再合并发现有冲突了
Auto-mergingfile1.txt
CONFLICT(content): Merge conflict in file1.txt
Automatic mergefailed; fix conflicts and then commit the result.
[root@git gittest]# vim file1.txt
[root@git gittest]# cat file1.txt
#再查看file1,文件内容如下,product和master提交的内容都在,并且有特殊符号表名了有冲突的地方,这时候只能手动解决冲突
my first file
the test something
product
[root@git gittest]# vim file1.txt
[root@git gittest]# cat file1.txt
my first file
the test something
master_ write
product_write
[root@git gittest]# git add file1.txt
[root@git gittest]# git commit -m "master and product"
[master bc03504]master and product
[root@git gittest]# git status
# On branch master
# Your branch isahead of 'origin/master' by 4 commits.
#
nothing to commit(working directory clean)
[root@git gittest]# git checkout product
Switched to branch'product'
[root@git gittest]# cat file1.txt
my first file
the test something
product_write
[root@git gittest]# git merge master
Updating95d6308..bc03504
Fast-forward
file1.txt | 1 +
1 files changed, 1 insertions(+), 0deletions(-)
[root@git gittest]# cat file1.txt #至此冲突解决
my first file
the test something
master_ write
product_write
|
|
|