人生不如意之事十有八九,合并分支往往也不是一帆风顺的。

我们准备新的分支newbranch.

LV@LV-PC MINGW32 /c/gitskill (master)
$ git checkout -b newbranch
Switched to a new branch 'newbranch'

修改readme.txt,在最后一行添加:

$ cat readme.txt
master分支内容
添加dev分支内容
分支合并测试

在分支newbranch上提交:

LV@LV-PC MINGW32 /c/gitskill (newbranch)
$ git add readme.txt

LV@LV-PC MINGW32 /c/gitskill (newbranch)
$ git commit -m "newbranch first commit"
[newbranch cccee34] newbranch first commit
1 file changed, 2 insertions(+), 1 deletion(-)

切换到master分支上:

$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)

在master分支上把readme.txt文件的最后一行添加:

master分支上的合并测试内容

添加,提交

LV@LV-PC MINGW32 /c/gitskill (master)
$ git add readme.txt

LV@LV-PC MINGW32 /c/gitskill (master)
$ git commit -m "master branch merge test"
[master 4bb4c5a] master branch merge test
1 file changed, 2 insertions(+), 1 deletion(-)

这种情况下,自动合并会出现冲突:

LV@LV-PC MINGW32 /c/gitskill (master)
$ git merge newbranch
Auto-merging readme.txt
CONFLICT (content): Merge conflict in readme.txt
Automatic merge failed; fix conflicts and then commit the result.

我们直接查看合并后的readme.txt文件内容:

$ cat readme.txt
master分支内容
添加dev分支内容
<<<<<<< HEAD
master分支上的合并测试内容
=======
分支合并测试
>>>>>>> newbranch

Git会用<<<<<<<,=======,>>>>>>>标记不同分支的内容,我们修改一下后保存

master分支内容
添加dev分支内容
master分支上的合并测试内容
分支合并测试

然后添加,提交:

LV@LV-PC MINGW32 /c/gitskill (master|MERGING)
$ git add readme.txt

LV@LV-PC MINGW32 /c/gitskill (master|MERGING)
$ git commit -m "branch merge"
[master f3d8f1e] branch merge

用带参数的git log也可以看到分支的合并情况:

LV@LV-PC MINGW32 /c/gitskill (master)
$ git log --graph --pretty=oneline --abbrev-commit
* f3d8f1e branch merge
|\
| * cccee34 newbranch first commit
* | 4bb4c5a master branch merge test
|/
* 0d0bbca dev first commit
* d5aea29 master first commit
* 023ee21 Initial commit

现在,删除newbranch分支:

LV@LV-PC MINGW32 /c/gitskill (master)
$ git branch -d newbranch
Deleted branch newbranch (was cccee34).

LV@LV-PC MINGW32 /c/gitskill (master)
$ git branch
* master

小结:当Git无法自动合并分支时,就必须首先解决冲突,解决冲突后,再提交,合并完成

可以用$ git log --graph 命令可以看到分支合并图。

Git合并分支出现的冲突解决的更多相关文章

  1. Git错误non-fast-forward后的冲突解决

    Git错误non-fast-forward后的冲突解决当要push代码到git时,出现提示: error:failed to push some refs to ... Dealing with “n ...

  2. git 合并分支到master

    git 合并分支到master   假如我们现在在dev分支上,刚开发完项目,执行了下列命令 git add .git commit -m ‘dev'git push -u origin dev 然后 ...

  3. 用git合并分支时,如何保持某些文件不被合并

    用git合并分支时,如何保持某些文件不被合并_fkaking的专栏-CSDN博客_git 合并分支 https://blog.csdn.net/fkaking/article/details/4495 ...

  4. git合并分支与解决冲突

    前提: 当前开发的分支为feature/20161129_317606_algoplatform_1,由于feature/20161130_322574_tmstools_1分支有新内容,所以准备将f ...

  5. Git 解决合并分支时的冲突

    参考链接:https://www.liaoxuefeng.com/wiki/896043488029600/900004111093344 创建分支时,新分支的文件内容建立在原分支的基础上,我们称这时 ...

  6. Git合并分支或者冲突

     假设冲突文件是 test/TestCase.php  下面分5种情况讨论. 1.本地不变.   然后远程别人有更新.   git pull   这种最简单,没有冲突,本地工作区直接更新   2.我本 ...

  7. git分支管理与冲突解决(转载)

    Git 分支管理和冲突解决 原文:http://www.cnblogs.com/mengdd/p/3585038.html 创建分支 git branch 没有参数,显示本地版本库中所有的本地分支名称 ...

  8. Git合并分支命令:git merge --ff

    今天研究了一下git merge命令常用参数,并分别用简单的例子实验了一下,整理如下: 输入git merge -h可以查看相关参数: --ff  快速合并,这个是默认的参数.如果合并过程出现冲突,G ...

  9. Git应用—03分支管理和冲突解决(转载)

    Git 分支管理和冲突解决 https://www.cnblogs.com/mengdd/p/3585038.html 创建分支 git branch 没有参数,显示本地版本库中所有的本地分支名称. ...

随机推荐

  1. Hive 安装过程中的问题

    org.apache.thrift.transport.TTransportException: Could not create ServerSocket on address 0.0.0.0/0. ...

  2. js 循环迭代定时器的执行次数和执行顺序??主要是因为js是单线程

    当定时器运行时即使每个迭代中执行的是setTimeout(.., 0),所有的回调函数依然是在循环结束后才会被执行 for语句开始赋值i=1;settimeout语句1000毫秒后把timer函数加入 ...

  3. HeartBeat源码安装

    只是写了安装流程,具体信息查看互联网; 环境: CentOS6.8 x86_64 min Heartbeat 3.0.6 http://hg.linux-ha.org/heartbeat-STABLE ...

  4. 外部系统集成BIEE

    1.外部系统集成BIEE 隐藏工具栏和仪表盘右上角的菜单 2.BIEE 11g 嵌入Iframe InIFrameRenderingMode有三种取值,分别是prohibit.sameDomainOn ...

  5. 转:详解JMeter正则表达式(1)

    1.概览 JMeter中包含范本匹配软件Apache Jakarta ORO .在Jakarta网站上有一些关于它的文档,例如a summary of the pattern matching cha ...

  6. DOS下导入导出MySQL备份

    导入: 1. cd d:\mysql\bin #cd 到 mysql 的 bin 目录下 2. mysql -u root -p mysql_db_name < d:\mysql\data\ba ...

  7. KMP详解之二

    KMP算法详解 如果机房马上要关门了,或者你急着要和MM约会,请直接跳到第六个自然段. 我们这里说的KMP不是拿来放电影的(虽然我很喜欢这个软件),而是一种算法.KMP算法是拿来处理字符串匹配的.换句 ...

  8. 读书笔记之ado.net entity framework

    提供了对数据访问的一种抽象层,是更加易于以编程的方式来操作及管理数据 有以下几种模式:Model First, Database First, and Code First 现在主要讨论code Fi ...

  9. 浙大pat 1011题解

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...

  10. HUST 1339 Reversal(字符串)

    题目链接 题解:将每个单词倒置,可以用char数组,然后用空格分隔,这里用的是string和stringstream. #include <cstdio> #include <ios ...