简体   繁体   English

合并提交而没有壁球与壁球选项

[英]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在请求合并分支时提供的选项: SmartGit 提交类型

On below graph you can see my example SmartGit graph output, containing:在下图中,您可以看到我的示例 SmartGit 图形输出,其中包含:

  • single master branch单个master分支
  • One branch merged to master with merge commit option一个分支通过merge commit选项合并到 master
  • One branch merged with simple commit option一个分支与simple 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

Merge commit (multiple parents):合并提交(多个父母):

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

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

--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 commitcommit有多个parent commit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM