git merge --squash和git cherry-pick有什么区别? [英] What's the difference between git merge --squash and git cherry-pick?

查看:163
本文介绍了git merge --squash和git cherry-pick有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在标准的主特征工作流程中工作,那么将特征分支挤入主分支与将特征分支挤入主分支之间有什么区别?

If I work in a standard master-feature workflow, what'd be the difference between squashing a feature branch into master and cherry-picking it into master?

示例分支:

m1 -- m2                 master
  \-- f1 -- f2           feature

我认为两者具有相同的输出,即

I think both have the same output ie

m1 -- m2 -- -- -- m3     master
  \-- f1 -- f2           feature

推荐答案

merge --squash cherry-pick 之间有两个重要区别:

There are two important differences between merge --squash and cherry-pick:

也就是说,如果您遇到上述情况,并且(在 master 上)执行了 git cherry-pick功能,则结果分支将如下所示:

That is, if you have a the situation you described above and you (on master) do a git cherry-pick feature, the resulting branch will look like this:

m1 -- m2 -- f2’           master
  \-- f1 -- f2           feature

这意味着主服务器上不存在对 f1 所做的更改(如果 f2 依赖它们,则挑选樱桃可能会失败.

This means the changes from f1 are not present on master (and cherry-picking possibly fails if f2 depends on them.

merge --squash 不会立即提交,而是创建所有更改的摘要并使它们准备提交.这实际上是完整分支更改的补丁,与 git diff m1..feature 将会显示的内容相同.

merge --squash does not immediately commit, instead it creates a summary of all the changes and makes them ready to commit. This is essentially a patch of your complete branch changes, the same that git diff m1..feature would show.

在我的机器上,快速测试给出了以下输出:

On my machine, a quick test gave this output:

$ test git:(master) git merge --squash testbranch
Squash commit -- not updating HEAD
Automatic merge went well; stopped before committing as requested

这里重要的一点是不更新HEAD",它是 speak ,表示我没有提交我所做的工作".实际上,第二句话更加人性化……

The important bit here is the "not updating HEAD", which is git-speak for "I didn’t commit the stuff I did". The second sentence in fact is far more user-friendly…

如果您想逐步进行开发(通过提交导致解决方案的所有小步骤,例如在每次成功的测试运行后进行提交),此功能将非常有用.在这种情况下,您的历史记录可能会变得混乱包含数百个单行提交.因此最好时不时进行合并-挤压提交(例如,在开发了一部分功能之后).

This feature is handy if you like to develop step-by-step (by committing all the little steps that led to the solution, e.g. with a commit after every successful test run. In this case, your history would likely get cluttered with hundreds of one-liner commits. So it is probably better to do a merge-squash-commit every now and then (e.g. after you have developed one bit of the functionality).

这篇关于git merge --squash和git cherry-pick有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆