git 合并提交而没有壁球与壁球选项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47089913/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Merge commit without squash vs with squash option
提问by Tomas
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
用作选择的客户。然而,我的团队成员坚持使用 git 原生、非商业 GUI。我们发现合并提交的外观存在一些差异。
Those are options that SmartGit
gives when requested to merge branch:
On below graph you can see my example SmartGit graph output, containing:
在下图中,您可以看到我的示例 SmartGit 图形输出,其中包含:
- single
master
branch - One branch merged to master with
merge commit
option - One branch merged with
simple commit
option
- 单
master
支 - 一个分支通过
merge commit
选项合并到 master - 一个分支与
simple commit
选项合并
One of branches (with_merge_branch
) is visualizing merge operation by joining branch with master via line. Second one (normal_commit_branch
) does not.
分支 ( with_merge_branch
) 之一是通过 line 将分支与 master 连接来可视化合并操作。第二个 ( normal_commit_branch
) 没有。
Question is, how to enforce both behaviors in native git commands? I.e. whats the difference between those two commits?
问题是,如何在本地 git 命令中强制执行这两种行为?即这两个提交之间有什么区别?
回答by Marina Liu
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
Merge commit (multiple parents):
合并提交(多个父母):
The command used is git merge branchname
. It's the default way to merge two branches.
使用的命令是git merge branchname
. 这是合并两个分支的默认方式。
When you merge develop
branch into master
branch by Merge commitin SmartGit (git merge develop
), the commit history will be:
当您通过SmartGit ( ) 中的合并提交将develop
分支合并到master
分支时,提交历史将是:git merge develop
A---B---C---D---M master
\ /
E---F---G develop
Simple commit (one parent, "squash"):
简单提交(一位家长,“壁球”):
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). 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).
生成工作树和索引状态,就像真正的合并发生一样(合并信息除外),但实际上不进行提交、移动 HEAD 或记录 $GIT_DIR/MERGE_HEAD(导致下一个 git commit 命令创建一个合并提交)。这允许您在当前分支之上创建单个提交,其效果与合并另一个分支相同(如果是章鱼则更多)。
When you merge develop
branch into master
branch by simple commitin 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 ( ) 中通过简单的 commit将develop
分支合并到master
分支时,它会将分支到分支的更改作为新的普通提交(就像真正的合并发生一样),并且提交历史将是:git merge develop --squash
develop
master
A---B---C---D---M master
\
E---F---G develop
回答by jsina
merge commits
are just commit
but the difference is they have more than one parents.
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 commits
只是commit
,不同的是他们有不止一个父母。如您所知,提交可能有也可能没有父提交,实际上merge commit
是commit
有多个parent commit
.