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 ...
随机推荐
- Git代码仓库的建立流程
Git作为现在比较流行的版本管理工具,其配置非常简单.方便. 下面举一个简单例子,说明如何在服务器上建立一个公共的git代码仓库. 1.确保服务器上已经打开ssh服务,可以用ps -e | grep ...
- Java compiler level does not match the version of the installed Java project facet 的解决方案
今天将MyEclipse升级到 9.1 后,打开原来的工作空间,原来所有的项目都前面都显示了一个小叉叉,代码中却没有任何错误.于从 problems 视图中查看错误信息,错误信息的"D ...
- Hive入门笔记---1.Hive简单介绍
1. Hive是什么 Hive是基于Hadoop的数据仓库解决方案.由于Hadoop本身在数据存储和计算方面有很好的可扩展性和高容错性,因此使用Hive构建的数据仓库也秉承了这些特性.这是来自官方的解 ...
- linux进程同步机制_转
转自:Linux进程同步机制 具体应用可参考:线程同步 IPC之信号量 为了能够有效的控制多个进程之间的沟通过程,保证沟通过程的有序和和谐,OS必须提供一 定的同步机制保证进程之间不会自说 ...
- 使用jsonp处理跨域问题
调用web接口,get请求,发现提示:No 'Access-Control-Allow-Origin' header is present on the requested resource. 这个和 ...
- oozie4.3.0+sqoop1.4.6实现mysql到hive的增量抽取
1.准备数据源 mysql中表bigdata,数据如下: 2. 准备目标表 目标表存放hive中数据库dw_stg表bigdata 保存路径为 hdfs://localhost:9000/user/h ...
- 微信小程序 - mixins
mixins 概念 可百度 参考 http://ask.seowhy.com/article/21007 大意和Python中的多重继承, java中的接口类似(java接口只是定义,实现需要子类自 ...
- URLDecoder: Incomplete trailing escape (%) pattern问题处理
http://blog.csdn.net/yangbobo1992/article/details/10076335 _________________________________________ ...
- SSIS 自测题-数据流控件类
说明:以下是自己的理解答案,不是标准的答案,如有不妥烦请指出. 有些题目暂时没有答案,有知道的请留言,互相学习,一起进步. 133.请描述一下 Conditional Split 的使 ...
- JDBC中,用于表示数据库连接的对象是。(选择1项)
JDBC中,用于表示数据库连接的对象是.(选择1项) A.Statement B.Connection C. DriverManager D.PreparedStatement 解答:B