master分支上有一个1.txt文件,进行修改后提交

$ cat 1.txt
1
11
12 $ echo 13 >> 1.txt $ git commit -a -m "modified 3.txt,add 13 in the end"
[master 4850577] modified 3.txt,add 13 in the end
1 file changed, 1 insertion(+)

test1分支是基于未修改的1.txt创建的,切换到test1分支上,修改1.txt并提交

$ git checkout test1

$ cat 1.txt
1
11
12 $ echo 133 >> 1.txt $ git commit -a -m "add 133 in the end"
[test1 2856268] add 133 in the end
1 file changed, 1 insertion(+)

可见,两次对1.txt的修改是不同的。在test1上的merge过程如下:

$ git merge master
Auto-merging 1.txt
CONFLICT (content): Merge conflict in 1.txt
Automatic merge failed; fix conflicts and then commit the result. $ git status
On branch test1
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 modified: 1.txt no changes added to commit (use "git add" and/or "git commit -a") $ cat 1.txt
1
11
12
<<<<<<< HEAD
133
=======
13
>>>>>>> master

如上所示,系统提示了1.txt的冲突。

开始修改。

vi 1.txt #删除冲突字符及修正冲突文本

$ cat 1.txt
1
11
12
133
13 git commit -a -m “modified 1.txt,add 133 & 13 in the end”

冲突解决结束。push即可。


这里再讲一下merge后log的commit id顺序问题。

merge是按照时间先后顺序进行排序的。

上述merge后,commit id 排列如下:

~****** (test1)
$ git log --pretty=oneline
2ab7554fe3ba533501a4d1438f63b696a286fef4 (HEAD -> test1) modified 1.txt
28562680162334a0cb3dfe6f78d05169b3fed9af add 133 in the end
4850577884cd4df8d868fb16bf993e904f7be4c5 (master) modified 3.txt,add 13 in the end

从历史操作可见4850577是在2856268之前的操作,所以merge后依然排列在2856268前面。

merge后的所有commit id是按照时间先后顺序排列的,这个和git rebase完全不同!关于这两者的差异会单独开贴!

有问题欢迎讨论!

git merge 的过程及冲突处理演示的更多相关文章

  1. git rebase和git merge的用法

    http://softlab.sdut.edu.cn/blog/subaochen/2016/01/git-rebase%E5%92%8Cgit-merge%E7%9A%84%E7%94%A8%E6% ...

  2. 学习 Git的使用过程

    原文链接: http://www.cnblogs.com/NickQ/p/8882726.html 学习 Git的使用过程 初次使用 git config --global user.name &qu ...

  3. git merge 合并分支

    git merge 用来做分支合并,将其他分支中的内容合并到当前分支中.比如分支结构如下: master / C0 ---- C1 ---- C2 ---- C4 \ C3 ---- C5 \ iss ...

  4. git merge合并分支; already up to date 现象, merger算法

    https://git-scm.com/book/zh/v2/Git-%E5%88%86%E6%94%AF-%E5%88%86%E6%94%AF%E7%9A%84%E6%96%B0%E5%BB%BA% ...

  5. git merge 及 git rebase的区别

    Git上合并代码有git merge 及 git rebase 两种方式. 前置知识点 Master分支:首先,代码库应该有一个.且仅有一个主分支.所有提供给用户使用的正式版本,都在这个主分支上发布. ...

  6. git pull和git merge区别&&Git冲突:commit your changes or stash them before you can merge. 解决办法

    http://blog.csdn.net/sidely/article/details/40143441 原文: http://www.tech126.com/git-fetch-pull/ Git中 ...

  7. git merge 冲突

    当前分支为 master 然后操作时: git merge dev 发现有文件冲突. 当我们倾向于使用dev 分支的代码时,可以使用以下命令: git checkout --theirs src/ma ...

  8. Git更新本地仓库及冲突"Commit your changes or stash them before you can merge"解决

    Git中从远程的分支获取最新的版本到本地有这样2个命令: 1. git fetch:相当于是从远程获取最新版本到本地,不会自动merge git fetch origin mastergit log  ...

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

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

随机推荐

  1. excel中vba求摩尔圆包线

    Dim f As Double, f1 As Double, f2 As Double, df As Double, oxy() As Double, R() As Double, k As Doub ...

  2. UVa 11427 Expect the Expected (数学期望 + 概率DP)

    题意:某个人每天晚上都玩游戏,如果第一次就䊨了就高兴的去睡觉了,否则就继续直到赢的局数的比例严格大于 p,并且他每局获胜的概率也是 p,但是你最玩 n 局,但是如果比例一直超不过 p 的话,你将不高兴 ...

  3. HDU 1536 S-Nim (组合游戏+SG函数)

    题意:针对Nim博弈,给定上一个集合,然后下面有 m 个询问,每个询问有 x 堆石子 ,问你每次只能从某一个堆中取出 y 个石子,并且这个 y 必须属于给定的集合,问你先手胜还是负. 析:一个很简单的 ...

  4. beforeunload事件

    window.addEventListener("beforeunload", function (e) { var confirmationMessage = "\o/ ...

  5. Kindeditor图片粘贴上传(chrome)

    kindeditor4.1.x版本已支持图片批量上传,不过传统的选文件上传的方式依然效率低下. 很多时候,编辑人员可能需要将一个文档中图片上传到网上,那么,按照传统的上传方法,他必须先将图片另存为到本 ...

  6. bzoj4873(最大权闭合子图)

    今天学了最大权闭合子图..然后找了这道题,发现完全不会..... 看了题解发现这种有诸如选了一个就一定要选另外的一些的限制又要求最优值的题有的可以转化成最大权闭合子图, 这个题我们首先想到不会选相交的 ...

  7. JDBC架构

    JDBC API支持两层和三层处理模型进行数据库访问,但在一般的JDBC体系结构由两层组成: JDBC API: 提供了应用程序对JDBC的管理连接. JDBC Driver API: 支持JDBC管 ...

  8. OpenGL中的渐变颜色绘图(应力可视化)

    #include <GL/glut.h> #include <iostream> #include <cmath> using namespace std; ; ; ...

  9. hihocoder 二分

    题目 一个简单的二分,只是想说明一下,如若要查找一个数组中某个数的下标可以直接用lower_bound()这个函数.只是要考虑到要查找的数不在数组中的这种情况. #include <cstdio ...

  10. js-数组方法push

    <script type="text/javascript">        var arr=[1,2,3,4,5]        arr.push(6,7)      ...