git使用详解
# git branchmaster
* product
# echo "product_write" >> file1.txt #在product上给file1新增一行并提交
# git add file1.txt
# git commit -m "product test"
product test
1 files changed, 1 insertions(+), 0deletions(-)
# git checkout master
Switched to branch'master'
Your branch isahead of 'origin/master' by 1 commit.
# cat file1.txt
my first file
the test something
# echo "master_ write" >> file1.txt #在master上也给file1新增一行
# 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.
# cat file1.txt
my first file
the test something
master_ write
# git add file1.txt
# git commit -m "master test"#master提交
master test
1 files changed, 1 insertions(+), 0deletions(-)
# git merge product #提交完之后再合并发现有冲突了
Auto-mergingfile1.txt
CONFLICT(content): Merge conflict in file1.txt
Automatic mergefailed; fix conflicts and then commit the result.
# vim file1.txt
# cat file1.txt
#再查看file1,文件内容如下,product和master提交的内容都在,并且有特殊符号表名了有冲突的地方,这时候只能手动解决冲突
my first file
the test something
product
# vim file1.txt
# cat file1.txt
my first file
the test something
master_ write
product_write
# git add file1.txt
# git commit -m "master and product"
master and product
# git status
# On branch master
# Your branch isahead of 'origin/master' by 4 commits.
#
nothing to commit(working directory clean)
# git checkout product
Switched to branch'product'
# cat file1.txt
my first file
the test something
product_write
# git merge master
Updating95d6308..bc03504
Fast-forward
file1.txt | 1 +
1 files changed, 1 insertions(+), 0deletions(-)
# cat file1.txt #至此冲突解决
my first file
the test something
master_ write
product_write
页:
[1]