合并不带南瓜和带南瓜选项的提交 [英] Merge commit without squash vs with squash option
问题描述
在日常工作中,我使用SmartGit
作为选择的客户端.但是,我的团队成员坚持使用git本机,非商业GUI.我们发现合并提交的外观有些差异.
On daily routine i use SmartGit
as client of choose. My team members however stick to git native, non commercial GUI. We discovered some differences in how our merge commits looks like.
这些是SmartGit
在请求合并分支时提供的选项:
Those are options that SmartGit
gives when requested to merge branch:
在下面的图形上,您可以看到我的示例SmartGit图形输出,其中包含:
On below graph you can see my example SmartGit graph output, containing:
- 单个
master
分支 - 使用
merge commit
选项合并到一个分支的主分支 - 一个分支与
simple commit
选项合并
- single
master
branch - One branch merged to master with
merge commit
option - One branch merged with
simple commit
option
其中一个分支(with_merge_branch
)通过通过行将分支与主节点联接来可视化合并操作.第二个(normal_commit_branch
)没有.
One of branches (with_merge_branch
) is visualizing merge operation by joining branch with master via line. Second one (normal_commit_branch
) does not.
问题是,如何在本机git命令中强制执行两种行为? IE.这两个提交有什么区别?
Question is, how to enforce both behaviors in native git commands? I.e. whats the difference between those two commits?
推荐答案
两种合并之间的区别只是提交历史记录中的不同(如您在图中显示的日志所示).
The difference between the two kinds of merge are only different in the commit history (as you showed the logs in graph).
让我们用图表来说明.合并之前,假定提交历史如下:
Let's illustrate by graphs. Assume the commit history as below before merging:
A---B---C---D master
\
E---F---G develop
合并提交(多个父母):
使用的命令是git merge branchname
.这是合并两个分支的默认方法.
Merge commit (multiple parents):
The command used is git merge branchname
. It's the default way to merge two branches.
在SmartGit(git merge develop
)中通过合并提交将develop
分支合并到master
分支时,提交历史记录将为:
When you merge develop
branch into master
branch by Merge commit in SmartGit (git merge develop
), the commit history will be:
A---B---C---D---M master
\ /
E---F---G develop
简单提交(一位家长,壁球"):
它使用--squash
选项合并两个分支,使用的命令是git merge branchname --squash
.
Simple commit (one parent, "squash"):
It merges two branches with --squash
option, the command used is git merge branchname --squash
.
产生工作树和索引状态,就好像发生了真正的合并(合并信息除外),但实际上并没有使 提交,移动HEAD或记录$ GIT_DIR/MERGE_HEAD(以引起 下一个git commit命令来创建合并提交).这使您能够 在当前分支的顶部创建一个提交,其效果是 与合并另一个分支(如果是章鱼,则更多)相同.
Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit, move the HEAD, or record $GIT_DIR/MERGE_HEAD (to cause the next git commit command to create a merge commit). This allows you to create a single commit on top of the current branch whose effect is the same as merging another branch (or more in case of an octopus).
在SmartGit(git merge develop --squash
)中通过简单提交将develop
分支合并到master
分支中时,它会将来自develop
分支的更改作为新的普通提交(好像发生了真正的合并),并且提交历史将为:
When you merge develop
branch into master
branch by simple commit in SmartGit (git merge develop --squash
), it get the changes from develop
branch into master
branch as a new ordinary commit (as if a real merge happened), and the commit history will be:
A---B---C---D---M master
\
E---F---G develop
这篇关于合并不带南瓜和带南瓜选项的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!