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 ...
随机推荐
- 下载编译安装Apache HTTP Server 2.4.23以及配置HTTP/HTTPS反向代理
http://blog.csdn.net/gangchengzhong/article/details/52910225 [注意,在编译make时出现的错误并不是文章中说的openssl的版本问题,而 ...
- Linq高级应用
Linq的应用为我们带来了很大的方便,提高了coding效率,最近看到了一个用linq写的数独游戏算法,让我看到了Linq写的是如此优雅,耳目一新的感觉,以前没有写过这样的代码,同时也感觉到原来Lin ...
- BZOJ 1444 [Jsoi2009]有趣的游戏 (AC自动机 + 概率DP + Gauss)
1444: [Jsoi2009]有趣的游戏 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1382 Solved: 498[Submit][Statu ...
- SpringBoot初探
一:项目创建 个人用的是IDEA来做Demo的: 1.先创建一个空项目,然后创建一个基于Maven的java application项目: 2.创建好后配置pom.xml文件并最终reimport & ...
- 20155205 《Java程序设计》实验三(敏捷开发与XP实践)实验报告
20155205 <Java程序设计>实验三(敏捷开发与XP实践)实验报告 一.实验内容及步骤 (一)使用Code菜单 在IDEA中使用工具(Code->Reformate Code ...
- Keil_uvision 基本使用教程
Keil C51 V9.00 即09年发布的最新版本uVision 4,版本外观改变比较大,可以使用以前的注册文件.如果全新安装,在VISTA或者WIN 7系统下,请使用管理员方式运行,然后注册即可无 ...
- uva12298(生成函数)
生成函数的一般应用: #include<iostream> #include<cstring> #include<cmath> #include<cstdio ...
- 使用Servlet动态生成验证码
最近在重新看了一遍servlert,看到篇优质博客推荐给大家:https://www.cnblogs.com/xdp-gacl/p/3798190.html 顺便把学习过程中的知识记录下来. 今天是如 ...
- java基础-day17
第06天 集合 今日内容介绍 u 集合&迭代器 u 增强for & 泛型 u 常见数据结构 u List子体系 第1章 集合&迭代器 1.1 集合体系结构 1.1 ...
- hdu 2642
这题应该就是标准的二维树状数组,应该没什么难度 处理一下x,y等于0的情况就过了 #include <iostream> #include <cstdio> #include ...