[英]Merge commit without squash vs with squash option
On daily routine i use SmartGit
as client of choose.在日常生活中,我使用
SmartGit
作为选择的客户端。 My team members however stick to git native, non commercial GUI.然而,我的团队成员坚持使用 git 原生、非商业 GUI。 We discovered some differences in how our merge commits looks like.
我们发现合并提交的外观存在一些差异。
Those are options that SmartGit
gives when requested to merge branch:这些是
SmartGit
在请求合并分支时提供的选项:
On below graph you can see my example SmartGit graph output, containing:在下图中,您可以看到我的示例 SmartGit 图形输出,其中包含:
master
branchmaster
分支merge commit
optionmerge commit
选项合并到 mastersimple commit
optionsimple commit
选项合并One of branches ( with_merge_branch
) is visualizing merge operation by joining branch with master via line.分支(
with_merge_branch
)之一是通过线将分支与主分支连接来可视化合并操作。 Second one ( normal_commit_branch
) does not.第二个(
normal_commit_branch
)没有。
Question is, how to enforce both behaviors in native git commands?问题是,如何在本地 git 命令中强制执行这两种行为? Ie 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
The command used is git merge branchname
.使用的命令是
git merge branchname
。 It's the default way to merge two branches.这是合并两个分支的默认方式。
When you merge develop
branch into master
branch by Merge commit in SmartGit ( git merge develop
), the commit history will be:当您通过 SmartGit 中的Merge commit (
git merge develop
) 将develop
分支合并到master
分支时,提交历史将是:
A---B---C---D---M master
\ /
E---F---G develop
It merges two branches with --squash
option, the command used is git merge branchname --squash
.它使用
--squash
选项合并两个分支,使用的命令是git merge branchname --squash
。
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).
生成工作树和索引状态,就好像真正的合并发生一样(合并信息除外),但实际上不进行提交、移动 HEAD 或记录 $GIT_DIR/MERGE_HEAD(导致下一个 git 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).
这允许您在当前分支之上创建单个提交,其效果与合并另一个分支相同(如果是章鱼则更多)。
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:当您通过 SmartGit 中的简单提交(
git merge develop --squash
)将develop
分支合并到master
分支时,它会从develop
分支到master
分支的更改作为新的普通提交(就像真正的合并发生一样),以及提交历史将是:
A---B---C---D---M master
\
E---F---G develop
merge commits
are just commit
but the difference is they have more than one parents. merge commits
只是commit
但不同的是他们有不止一个父母。 as you know commits may or may not have parent commit, in fact the merge commit
is the commit
that have more than one parent commit
.如你所知提交可能会或可能不会有家长承诺,实际上
merge commit
是commit
有多个parent commit
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.