标签:git git分支合并 git分支合并冲突 git分支合并种类 git快速合并与普通合并
Git 分支合并冲突及合并分类##创建分支datagrand
git checkout -b datagrand
Switched to a new branch ‘datagrand‘
git branch -a
master
\* datagrand
##在datagrand分支上创建文件
echo "this is git file!" > read.txt
git add read.txt
git commit -m "add a new file"
git push -u origin datagrand
##切换到master分支,建立read.txt文件
echo "my name is wtf" > read.txt
git add read.txt
git commit -m "add a new file"
git push
##合并分支
##在master分支上操作
git merge datagrand
##说明:这种情况下,Git无法执行“快速合并”,只能试图把各自的修改合并起来,但这种合并就可能会有冲突,报错如下:
Auto-merging read.txt
CONFLICT (add/add): Merge conflict in read.txt
Automatic merge failed; fix conflicts and then commit the result.
##说明:Git告诉我们read.txt文件存在冲突,必须手动解决冲突后再提交。
##查看下当前分支状态
git status
On branch master
Your branch is up-to-date with ‘origin/master‘.
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both added: read.txt
no changes added to commit (use "git add" and/or "git commit -a")
##查看一下readme.txt中的内容
cat read.txt
<<<<<<< HEAD
my name is wtf!
=======
this is git file!
\>>>>>>> datagrand
##说明:Git用<<<<<<<,=======,>>>>>>>标记出不同分支的内容,让我们选择要保留的内容,下面我们修改一下readme.txt,再次提交。
##操作步骤如下:
vim read.txt
git add read.txt
git commit -m "fixed"
[master 935e613] fixed
git status
On branch master
Your branch is ahead of ‘origin/master‘ by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
cat read.txt
this is git file!
##分支合并
git merge datagrand
##查看合并后状态
git status
On branch master
Your branch is ahead of ‘origin/master‘ by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
git branch -d datagrand
Deleted branch datagrand (was 3299654).
##查看一下分支合并信息
git log --graph --pretty=oneline --abbrev-commit
\* 935e613 (HEAD -> master) fixed
|| * 3299654 (origin/datagrand) add a new file
\* | d4f781c (origin/master) add a file read
\* | ddb3e06 Delete read.txt
\* | 13bfb1c add a file read
|/
标签:git git分支合并 git分支合并冲突 git分支合并种类 git快速合并与普通合并
原文地址:http://blog.51cto.com/wutengfei/2091410