git merge 的过程及冲突处理演示
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 的过程及冲突处理演示的更多相关文章
- 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% ...
- 学习 Git的使用过程
原文链接: http://www.cnblogs.com/NickQ/p/8882726.html 学习 Git的使用过程 初次使用 git config --global user.name &qu ...
- git merge 合并分支
git merge 用来做分支合并,将其他分支中的内容合并到当前分支中.比如分支结构如下: master / C0 ---- C1 ---- C2 ---- C4 \ C3 ---- C5 \ iss ...
- 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% ...
- git merge 及 git rebase的区别
Git上合并代码有git merge 及 git rebase 两种方式. 前置知识点 Master分支:首先,代码库应该有一个.且仅有一个主分支.所有提供给用户使用的正式版本,都在这个主分支上发布. ...
- 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中 ...
- git merge 冲突
当前分支为 master 然后操作时: git merge dev 发现有文件冲突. 当我们倾向于使用dev 分支的代码时,可以使用以下命令: git checkout --theirs src/ma ...
- Git更新本地仓库及冲突"Commit your changes or stash them before you can merge"解决
Git中从远程的分支获取最新的版本到本地有这样2个命令: 1. git fetch:相当于是从远程获取最新版本到本地,不会自动merge git fetch origin mastergit log ...
- Git合并分支命令:git merge --ff
今天研究了一下git merge命令常用参数,并分别用简单的例子实验了一下,整理如下: 输入git merge -h可以查看相关参数: --ff 快速合并,这个是默认的参数.如果合并过程出现冲突,G ...
随机推荐
- mysql学习之路_连接查询
回顾 列属性:主键,自增长,唯一键. 关系:一对一,一对多,多对多 三层范式: 1NF:字段设计必须符合原子性 2NF:不存在部分依赖(没有复合主键) 3NF:不存在传递依赖(实体单独成表) 逆规范化 ...
- BZOJ 2005 [Noi2010]能量采集 (数学+容斥 或 莫比乌斯反演)
2005: [Noi2010]能量采集 Time Limit: 10 Sec Memory Limit: 552 MBSubmit: 4493 Solved: 2695[Submit][Statu ...
- MyBatis(一)helloWorld程序
一.准备两个jar包,第一个:下载myBatis-3.3.1.jar,这里是在CSDN网站处下载的,因为官网打不开.第二个:mysql-connector-java-5.0.8-bin.jar,这个j ...
- kepware http接口 nodejs开发
读取某变量的值(native var http = require("http"); var options = { "method": "GET&q ...
- mysql 中 datetime和 timestamp的区别
DATETIME日期和时间的组合.支持的范围是'1000-01-01 00:00:00'到'9999-12-31 23:59:59'.MySQL以'YYYY-MM-DD HH:MM:SS'格式显示DA ...
- Hdu2819 Swap
Swap Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- utf8.php
<?php /** * */ class Utf8 { function __construct() { global $CFG; if( preg_match('/./u', '') === ...
- excel冻结窗格
编辑excel时冻结窗格可以大大增加可读性.每个sheet都应该加上. 第一份工作的时候,上司比较严格,还因为这个挨过几次骂.所以这个技巧大家一定要掌握 方法很简单: 选中首行:视图 -- 冻结窗格 ...
- CentOS7安装BugFree
1. 安装apache yum install httpd 2. 安装mysql yum install mysql yum install mysql-server 注意: 1)已安装mysql的跳 ...
- A - Excellent Team
Description Gibbs: Next! First Pirate: My wife ran off with my dog and I'm drunk for a month. Gibbs: ...