在日常工作中,我选择使用 SmartGit
作为客户端。然而,我的团队成员坚持使用 git 原生的非商业 GUI。我们发现我们的 merge 提交看起来有些不同。
这些是 SmartGit
在请求 merge 分支时提供的选项:
在下图中,您可以看到我的示例 SmartGit 图形输出,其中包含:
- 单个
master
分支 - 一个分支通过
merge commit
选项 merge 到master - 一个分支与
简单提交
选项 merge
其中一个分支 (with_merge_branch
) 通过将分支与 master 连接起来来可视化 merge 操作。第二个 (normal_commit_branch
) 没有。
问题是,如何在原生 git 命令中强制执行这两种行为? IE。这两个提交之间有什么区别?
最佳答案
这两种 merge 之间的区别只是在提交历史上有所不同(正如您在图中显示的日志)。
让我们用图表来说明。假设 merge 前的提交历史如下:
A---B---C---D master
\
E---F---G develop
merge 提交(多个 parent ):
使用的命令是git merge branchname
。这是 merge 两个分支的默认方式。
当你在SmartGit中通过Merge commit将develop
分支 merge 到master
分支时(git merge develop
),提交历史将是:
A---B---C---D---M master
\ /
E---F---G develop
简单提交(一个父级,“squash”):
它用--squash
选项 merge 两个分支,使用的命令是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).
当您在 SmartGit 中通过简单提交将 develop
分支 merge 到 master
分支时(git merge develop --squash
),它将从 develop
分支到 master
分支的更改作为新的普通提交(就像发生了真正的 merge 一样),提交历史将是:
A---B---C---D---M master
\
E---F---G develop
关于git - 不使用 squash 与使用 squash 选项 merge 提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47089913/