git之merge和rebase的区别
merge合并
# merge操作 第一步:
# 先创建一个目录,在主分支提交3个txt文件
[root@luchuangao]# mkdir oldboy
[root@luchuangao]# git init 初始化
[root@luchuangao]# echo "a" > a.txt
[root@luchuangao]# echo "b" > b.txt
[root@luchuangao]# echo "c" > c.txt
[root@luchuangao]# git add a.txt
[root@luchuangao]# git commit -m 'a'
[master(根提交) ac03ef7] a
1 file changed, 1 insertion(+)
create mode 100644 a.txt
[root@luchuangao]# git add b.txt
[root@luchuangao]# git commit -m 'b'
[master 65c273b] b
1 file changed, 1 insertion(+)
create mode 100644 b.txt
[root@luchuangao]# git add c.txt
[root@luchuangao]# git commit -m 'c'
[master ddb2007] c
1 file changed, 1 insertion(+)
create mode 100644 c.txt 第二步:
# 创建并切换到testing分支,并提交2个txt文件
[root@luchuangao]# git checkout -b testing
切换到一个新分支 'testing'
[root@luchuangao]# echo "test1" > test1.txt
[root@luchuangao]# echo "test2" > test2.txt
[root@luchuangao]# git add test1.txt
[root@luchuangao]# git commit -m 'test1'
[testing 4d18278] test1
1 file changed, 1 insertion(+)
create mode 100644 test1.txt
[root@luchuangao]# git add test2.txt
[root@luchuangao]# git commit -m 'test2'
[testing 2c7ef37] test2
1 file changed, 1 insertion(+)
create mode 100644 test2.txt # 查看testing分支日志
[root@proxy-nfs oldboy]# git log
commit 2c7ef374134f0158fab77137717d7ba1c1281a36
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:42:26 2017 +0800 test2 commit 4d182786a2199f10351dd69e819d6878513c8456
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:42:17 2017 +0800 test1 commit ddb20076027cca6b310a30468445ce82e96dcbcd
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:41:13 2017 +0800 c commit 65c273b1512cbad0c4325d21f1cd6c421d14f2b3
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:41:07 2017 +0800 b commit ac03ef772d4e01914d0917676d2f33eca8c0bb11
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:40:57 2017 +0800 a 第三步:
# 切换至主分支,再在主分支提交2个txt文件
[root@proxy-nfs oldboy]# git checkout master
切换到分支 'master'
[root@proxy-nfs oldboy]# echo "master1" > master1.txt
[root@proxy-nfs oldboy]# echo "master2" > master2.txt
[root@proxy-nfs oldboy]# git add master1.txt
[root@proxy-nfs oldboy]# git commit -m 'master1'
[master 9353089] master1
1 file changed, 1 insertion(+)
create mode 100644 master1.txt
[root@proxy-nfs oldboy]# git add master2.txt
[root@proxy-nfs oldboy]# git commit -m 'master2'
[master 1cca7b6] master2
1 file changed, 1 insertion(+)
create mode 100644 master2.txt # 查看master分支日志
[root@proxy-nfs oldboy]# git log
commit 1cca7b62bbb5b7f7e62a7d2c55a76618109bbffc
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:43:37 2017 +0800 master2 commit 9353089557089753359445242c32352fcb6b32f0
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:43:30 2017 +0800 master1 commit ddb20076027cca6b310a30468445ce82e96dcbcd
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:41:13 2017 +0800 c commit 65c273b1512cbad0c4325d21f1cd6c421d14f2b3
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:41:07 2017 +0800 b commit ac03ef772d4e01914d0917676d2f33eca8c0bb11
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:40:57 2017 +0800 a 第四步:
# 合并testing,不做修改,直接wq保存
[root@luchuangao oldboy]# git merge testing
Merge branch 'testing' # 请输入一个提交信息以解释此合并的必要性,尤其是将一个更新后的上游分支
# 合并到主题分支。
#
# 以 '#' 开头的行将被忽略,而且空提交说明将会终止提交。 ".git/MERGE_MSG" 6L, 238C written
Merge made by the 'recursive' strategy.
test1.txt | 1 +
test2.txt | 1 +
2 files changed, 2 insertions(+)
create mode 100644 test1.txt
create mode 100644 test2.txt # 查看master分支日志,多了一个“Merge branch 'testing'” 日志记录
[root@luchuangao oldboy]# git log
commit ea4c21bd398bd1a766bc8a498df44c8e2dc4993e
Merge: 1cca7b6 2c7ef37
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:51:14 2017 +0800 Merge branch 'testing' commit 1cca7b62bbb5b7f7e62a7d2c55a76618109bbffc
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:43:37 2017 +0800 master2 commit 9353089557089753359445242c32352fcb6b32f0
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:43:30 2017 +0800 master1 commit 2c7ef374134f0158fab77137717d7ba1c1281a36
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:42:26 2017 +0800 test2 commit 4d182786a2199f10351dd69e819d6878513c8456
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:42:17 2017 +0800 test1 commit ddb20076027cca6b310a30468445ce82e96dcbcd
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:41:13 2017 +0800 c commit 65c273b1512cbad0c4325d21f1cd6c421d14f2b3
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:41:07 2017 +0800 b commit ac03ef772d4e01914d0917676d2f33eca8c0bb11
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:40:57 2017 +0800 a
[root@luchuangao oldboy]#
rebase变基
# rebase操作 第一步:
# 先创建一个目录,在主分支提交3个txt文件
[root@luchuangao ~]# cd oldgirl/
[root@luchuangao oldgirl]# git init
初始化空的 Git 版本库于 /root/oldgirl/.git/
[root@luchuangao oldgirl]# echo "a" > a.txt
[root@luchuangao oldgirl]# echo "b" > b.txt
[root@luchuangao oldgirl]# echo "c" > c.txt
[root@luchuangao oldgirl]# git add a.txt
[root@luchuangao oldgirl]# git commit -m 'a'
[master(根提交) c54fa4b] a
1 file changed, 1 insertion(+)
create mode 100644 a.txt
[root@luchuangao oldgirl]# git add b.txt
[root@luchuangao oldgirl]# git commit -m 'b'
[master c889368] b
1 file changed, 1 insertion(+)
create mode 100644 b.txt
[root@luchuangao oldgirl]# git add c.txt
[root@luchuangao oldgirl]# git commit -m 'c'
[master 60fe420] c
1 file changed, 1 insertion(+)
create mode 100644 c.txt 第二步:
# 创建并切换到testing分支,并提交2个txt文件
[root@luchuangao oldgirl]# git checkout -b testing
切换到一个新分支 'testing'
[root@luchuangao oldgirl]# echo "test1" > test1.txt
[root@luchuangao oldgirl]# echo "test2" > test2.txt
[root@luchuangao oldgirl]# git add test1.txt
[root@luchuangao oldgirl]# git commit -m 'test1'
[testing 65f10cf] test1
1 file changed, 1 insertion(+)
create mode 100644 test1.txt
[root@luchuangao oldgirl]# git add test2.txt
[root@luchuangao oldgirl]# git commit -m 'test2'
[testing 747599f] test2
1 file changed, 1 insertion(+)
create mode 100644 test2.txt
[root@luchuangao oldgirl]# git log
commit 747599fba4c46673f8aae88828d2ac884e3cb2a4
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:56:21 2017 +0800 test2 commit 65f10cfc43af5d364a24907564e0eb0898edf2e1
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:56:00 2017 +0800 test1 commit 60fe4206ed68a3c7a0a2473310f9430e233ee1e9
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:54:21 2017 +0800 c commit c889368e57e171ca58dcfc98fa7d742fe22fa362
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:54:16 2017 +0800 b commit c54fa4bff7733175ef67b7db6b222464039aafb4
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:54:10 2017 +0800 a 第三步:
# 切换至主分支,再在主分支提交2个txt文件
[root@luchuangao oldgirl]# git checkout master
切换到分支 'master'
[root@luchuangao oldgirl]# echo "master1" > master1.txt
[root@luchuangao oldgirl]# echo "master2" > master2.txt
[root@luchuangao oldgirl]# git add master1.txt
[root@luchuangao oldgirl]# git commit -m 'master1'
[master ca28eb9] master1
1 file changed, 1 insertion(+)
create mode 100644 master1.txt
[root@luchuangao oldgirl]# git add master2.txt
[root@luchuangao oldgirl]# git commit -m 'master2'
[master a48b977] master2
1 file changed, 1 insertion(+)
create mode 100644 master2.txt
[root@luchuangao oldgirl]# git log
commit a48b977c1c0459066cf20bbd28d77021e85ab15c
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:57:25 2017 +0800 master2 commit ca28eb9251012b0501a2678e42e765dc5fb9b81c
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:57:20 2017 +0800 master1 commit 60fe4206ed68a3c7a0a2473310f9430e233ee1e9
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:54:21 2017 +0800 c commit c889368e57e171ca58dcfc98fa7d742fe22fa362
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:54:16 2017 +0800 b commit c54fa4bff7733175ef67b7db6b222464039aafb4
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:54:10 2017 +0800 a 第四步:
# 合并testing
[root@luchuangao oldgirl]# git rebase testing
首先,重置头指针以便在上面重放您的工作...
正应用:master1
正应用:master2 # 查看master分支日志,发现根本没有合并得日志记录
[root@luchuangao oldgirl]# git log
commit e28b92283b6dff9af42446183e121cc379f79e7b
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:57:25 2017 +0800 master2 commit 6e49a215c918e3e3ce229bf4aff1bb8608f03d4e
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:57:20 2017 +0800 master1 commit 747599fba4c46673f8aae88828d2ac884e3cb2a4
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:56:21 2017 +0800 test2 commit 65f10cfc43af5d364a24907564e0eb0898edf2e1
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:56:00 2017 +0800 test1 commit 60fe4206ed68a3c7a0a2473310f9430e233ee1e9
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:54:21 2017 +0800 c commit c889368e57e171ca58dcfc98fa7d742fe22fa362
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:54:16 2017 +0800 b commit c54fa4bff7733175ef67b7db6b222464039aafb4
Author: luchuangao <luchuangao@126.com>
Date: Fri Oct 27 20:54:10 2017 +0800 a
merge与rebase的区别
由以上操作第四步,可以很明显看出,merge和rebase得区别。
merge有“Merge branch 'testing'”日志记录,而rebase木有。
merge 合并两个或更多开发历史。
rebase 本地提交转移至更新后的上游分支中。
使用场景:
merge可以保存历史记录,记录什么时间合并的,从哪个分支合并过来得,数据不会变动,即使删除testing分支,数据还是存在得。
rebase隐藏了提交细节,好像没开过分支一样。
git之merge和rebase的区别的更多相关文章
- Git分支merge和rebase的区别
Git merge是用来合并两个分支的. git merge b # 将b分支合并到当前分支 同样 git rebase b,也是把 b分支合并到当前分支 原理 如下: 假设你现在基于远程分支&quo ...
- [git]merge和rebase的区别
前言 我从用git就一直用rebase,但是新的公司需要用merge命令,我不是很明白,所以查了一些资料,总结了下面的内容,如果有什么不妥的地方,还望指正,我一定虚心学习. merge和rebase ...
- merge和rebase的区别
前言 我从用git就一直用rebase,但是新的公司需要用merge命令,我不是很明白,所以查了一些资料,总结了下面的内容,如果有什么不妥的地方,还望指正,我一定虚心学习. merge和rebase ...
- 图解 Git 基本命令 merge 和 rebase
Git 基本命令 merge 和 rebase,你真的了解吗? 前言 Git 中的分支合并是一个常见的使用场景. 仓库的 bugfix 分支修复完 bug 之后,要回合到主干分支,这时候两个分支需要合 ...
- git——merge和rebase的区别
参考http://www.jianshu.com/p/129e721adc6e 我在公司里看到其他同事都使用git pull --rebase拉取远程代码,而我总是用git pull,也有同事和我说过 ...
- Git Step by Step – (8) Git的merge和rebase
前面一篇文章中提到了"git pull"等价于"git fetch"加上"git merge",然后还提到了pull命令支持rebase模式 ...
- [Git] git merge和rebase的区别
git merge 会生成一个新得合并节点,而rebase不会 比如: D---E test / A---B---C---F master 使用merge合并, 为分支合并自动识别出最佳的同源合并点: ...
- git merge 与 rebase 的区别
http://gitbook.liuhui998.com/4_2.html merge rebase
- 关于Git的merge和rebase命令解析
git rebase是对提交执行变基的操作.即可以实现将指定范围的提交"嫁接"到另外一个提交智商. 其常用的命令格式有: 用法1:git rebase --onto <new ...
随机推荐
- jquery flexslider 轮播插件
去官网下载最新的 https://www.woothemes.com/flexslider/ 引入 css 和 js api $(window).load(function() { $('.flexs ...
- 改进cocos2dx中lua读ccb的方法
cocos2dx自带的CCBProxy真弱,还好提供了一个CCBReaderLoader.lua,但是也不好用, 于是修改了一下CCBReaderLoader,下面直接贴代码了. function N ...
- Hadoop-2.2.0中文文档—— MapReduce 下一代 - Encrypted Shuffle
简单介绍 Encrypted Shuffle capability (加密洗牌功能? )同意用HTTPS 和 可选的client验证 (也称作双向的 HTTPS, 或有client证书的 HTTPS) ...
- HeadFirst 设计模式 04 工厂模式
除了 new 操作符之外, 还有更多创造对象的方法. 工厂处理创建对象的细节. 这么做的目的是为了抽象, 例如把创建比萨的代码包装进一个类, 当以后实现改变时, 只需修改这个类即可. 利用静态方法定义 ...
- git 停止在12% writing objects 怎么回事?
git 停止在12% writing objects 怎么回事? 输入以下代码试一下: git config --global http.postBuffer 524288000
- RAII in C++
在C++中,如果对一个块直接分配资源,而且在释放资源之前发生异常,那么这些资源在栈展开(注1)期间将不会得到释放.例如,一个块可以通过调用new动态分配内存,如果该块因异常退出,编译器将不会删除该指针 ...
- RabbitMQ用户角色及权限控制 -2
1.RabbitMQ的用户角色分类: none.management.policymaker.monitoring.administrator none 不能访问 management plugin ...
- [python]常用的几个包
http://dev.mysql.com/doc/connector-python/en/connector-python-tutorial-cursorbuffered.html https://d ...
- Spring_day01--注入对象类型属性(重点)_P名称空间注入_注入复杂类型属性_IOC和DI区别_Spring整合web项目原理
注入对象类型属性(重点) Action要new一个service对象,Service中又要new一个Dao对象,现在把new的过程交给spring来操作 1 创建service类和dao类 (1)在s ...
- ios开发--图文混排(富文本)
最近准备接一个编辑类的app,所以就查了下相关的功能,并自己试验了下: /** iOS 6之前:CoreText,纯C语言,极其蛋疼 iOS 6开始:NSAttributedString,简单易用 i ...