合并提交与正常提交 [英] Merge commit vs normal commit

查看:198
本文介绍了合并提交与正常提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在日常工作中,我使用 SmartGit 作为选择的客户端。然而,我的团队成员坚持使用git本地非商业GUI。我们在合并提交的样子中发现了一些不同之处。



这些选项是 SmartGit 在请求合并时给出的选项分行:



在下图中,您可以看到我的示例SmartGit图形输出,其中包含:




  • 单一$ master 分支

  • 合并提交选项
  • 与$ 简单提交选项合并的一个分支 li>


其中一个分支( with_merge_branch )通过将分支连接到主可视化合并操作线。第二个( normal_commit_branch )没有。



问题是,如何在本地git命令中执行这两种行为?即这两个提交之间的区别是什么?

解决方案

两种合并之间的区别仅在历史(如您在图表中显示日志)。



让我们用图表来说明。在合并之前假设提交历史记录如下所示:

  A --- B --- C --- D master 
\
E --- F --- G开发



合并提交(多个父母):



使用的命令是 git merge branchname 。这是合并两个分支的默认方式。



develop 分支合并到 master 在SmartGit( git merge develop )中由合并提交分支,提交历史记录为:

  A --- B --- C --- D --- M主人
\ /
E- --F --- G开发



简单提交(一个父代,squash): h3>

它使用 - squash 选项合并两个分支,使用的命令是 git merge branchname - -squash


- squash



生成工作树和索引状态,就好像发生了真正的合并(合并除外信息),但实际上并没有做
a提交,移动HEAD,或者记录$ GIT_DIR / MERGE_HEAD(导致
next git commit命令创建一个合并提交)。这允许你
在当前分支的顶部创建一个单独的提交,其作用是
与合并另一个分支相同(或者在章鱼的情况下更多)。


开发分支合并到 master 分支由<在SmartGit中( git merge develop --squash ),它会从 develop >分支到 master 分支作为新的普通提交(就像真正的合并发生了一样),并且提交历史记录为:

  A --- B --- C --- D --- M主人
\
E --- F --- G开发


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.

Those are options that SmartGit gives when requested to merge branch:

On below graph you can see my example SmartGit graph output, containing:

  • single master branch
  • One branch merged to master with merge commit option
  • One branch merged with simple commit option

One of branches (with_merge_branch) is visualizing merge operation by joining branch with master via line. Second one (normal_commit_branch) does not.

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

Merge commit (multiple parents):

The command used is 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:

A---B---C---D---M  master
     \         /
      E---F---G    develop

Simple commit (one parent, "squash"):

It merge two branches with --squash option, the command used is 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). 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:

A---B---C---D---M  master
     \                 
      E---F---G    develop

这篇关于合并提交与正常提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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