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. lf-8.4 数据的增删改

    MySQL数据操作: DML 在MySQL管理软件中,可以通过SQL语句中的DML语言来实现数据的操作,包括 使用INSERT实现数据的插入 UPDATE实现数据的更新 使用DELETE实现数据的删除 ...

  2. 【王者荣耀之IT大神版】铭文说明

    铭文共分五级: 一级:仅有老师提供的笔记 二级:添加了自己的听课笔记 三级:添加问题+解决方案(常遇到的问题以及自己实践上遇到的问题,排位赛遇到的遗忘点) 四级:熟记铭文与并添加联想学过的知识 五级: ...

  3. asp.net文件上传下载

    泽优大文件上传产品测试 泽优大文件上传控件up6,基于php开发环境测试. 开发环境:HBuilder 服务器:wamp64 数据库:mysql 可视化数据库编辑工具:Navicat Premium ...

  4. Linux上的TIME_WAIT和tcp_fin_timeout

    当Linux服务器的TIME_WAIT过多时,通常会想到去修改参数降低TIME_WAIT时长,以减少TIME_WAIT数量,但Linux并没有提供这样的接口,除非重新编译内核. Linux默认的TIM ...

  5. Forward团队-爬虫豆瓣top250项目-团队编程项目开发环境搭建过程

    本次结对编程和团队项目我都需要用python环境,所以环境的搭建是一样的.(本文部分内容引用自己博客:http://www.cnblogs.com/xingyunqi/p/7527411.html) ...

  6. 基于SVG+AJAX的网页数据监控

    这个是前一阵做的一个火灾报警主机数据网页监控,前后台主要耗时5小时.绘图2小时,配置后端采集端1小时,测试2小时. 用的SVG,上面画的指示灯可以实时显示传感器的状态. 用开源方案实现. 如果集成到自 ...

  7. noip第1课资料

  8. nutch相关目录说明

    Nutch数据包含3个目录结构,分别是: 1.Crawldb:用于存储Nutch将要检索的url信息,以及检索状态(是否检索.何时检索) 2.Linkdb:用于存储每一个url所包含的超链接信息(包括 ...

  9. Alpha阶段scrum meeting七天冲刺博客-天冷记得穿秋裤队

    Alpha阶段scrum meeting七天冲刺博客 day url 第一天 https://www.cnblogs.com/laomiXD/articles/9874052.html 第二天 htt ...

  10. [leetcode 120]triangle 空间O(n)算法

    1 题目 Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjac ...