[Git] git merge之squash

简介:

reference : https://www.cnblogs.com/ungshow/p/3515161.html

看CM源码时,发现历史记录里有很多squash,于是google了解了一下。

Git相对于CVS和SVN的一大好处就是merge非常方便,只要指出branch的名字就好了,如:

1
2
3
4
$ git checkout another
# modify, commit, modify, commit ...
$ git checkout master
$ git merge another

 但是,操作方便并不意味着这样操作就是合理的,在某些情况下,我们应该优先选择使用--squash选项,如下:

1
2
$ git merge --squash another
$ git commit -m  "message here"

 --squash 选项的含义是:本地文件内容与不使用该选项的合并结果相同,但是不提交、不移动HEAD,因此需要一条额外的commit命令。

其效果相当于将another分支上的多个commit合并成一个,放在当前分支上,原来的commit历史则没有拿过来。

1
2
3
Note:
 
判断是否使用--squash选项最根本的标准是,待合并分支上的历史是否有意义。

 

如果在开发分支上提交非常随意,甚至写成微博体,那么一定要使用--squash选项。版本历史记录的应该是代码的发展,而不是开发者在编码时的活动。

只有在开发分支上每个commit都有其独自存在的意义,并且能够编译通过的情况下(能够通过测试就更完美了),才应该选择缺省的合并方式来保留commit历史。

 

分类:  Git
本文转自demoblog博客园博客,原文链接http://www.cnblogs.com/0616--ataozhijia/p/8024740.html如需转载请自行联系原作者

demoblog
相关文章
|
开发工具 git
git merge和git rebase异同
git merge和git rebase异同
413 0
|
8月前
|
存储 安全 开发工具
深度解决 Git “fatal: refusing to merge unrelated histories” 错误解析什么是历史分支优雅草卓伊凡
深度解决 Git “fatal: refusing to merge unrelated histories” 错误解析什么是历史分支优雅草卓伊凡
722 4
深度解决 Git “fatal: refusing to merge unrelated histories” 错误解析什么是历史分支优雅草卓伊凡
|
5月前
|
开发工具 git
Git版本控制工具合并分支merge命令操作流程
通过以上步聚焦于技术性和操作层面指南(guidance), 可以有效管理项目版本控制(version control), 并促进团队协作(collaboration).
1213 15
|
7月前
|
API 开发工具 git
使用git pull遇到Automatic merge failed; fix conflicts and then commit the result.解决方案卓伊凡
使用git pull遇到Automatic merge failed; fix conflicts and then commit the result.解决方案卓伊凡
407 0
使用git pull遇到Automatic merge failed; fix conflicts and then commit the result.解决方案卓伊凡
|
开发工具 git
git的rebase和merge的区别
通过这些内容和示例,您可以深入理解Git的 `rebase`和 `merge`操作及其区别,选择合适的方法进行分支管理,提高版本控制的效率和规范性。希望这些内容对您的学习和工作有所帮助。
2516 5
|
开发工具 git 开发者
【git merge/rebase】详解合并代码、解决冲突
【git merge/rebase】详解合并代码、解决冲突
3167 0
|
Ubuntu Linux 开发工具
idea使用git提交代码报异常refusing to merge unrelated histories和unknown option `allow-unrelated-histories‘
idea使用git提交代码报异常refusing to merge unrelated histories和unknown option `allow-unrelated-histories‘
|
开发工具 git 开发者
|
安全 开发工具 git
蓝易云 - git rebase和merge区别
在选择使用Merge还是Rebase时,需要根据具体的工作流程和团队的规定来决定。一般来说,如果你想保持完整的历史记录并且避免可能的冲突,你应该使用Merge。如果你想要一个干净的、线性的历史记录,你可以使用Rebase。
773 4