git - 不使用 squash 与使用 squash 选项 merge 提交

标签 git merge version-control smartgit

在日常工作中,我选择使用 SmartGit 作为客户端。然而,我的团队成员坚持使用 git 原生的非商业 GUI。我们发现我们的 merge 提交看起来有些不同。

这些是 SmartGit 在请求 merge 分支时提供的选项: SmartGit commits type

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

  • 单个 master 分支
  • 一个分支通过merge commit选项 merge 到master
  • 一个分支与简单提交选项 merge

其中一个分支 (with_merge_branch) 通过将分支与 master 连接起来来可视化 merge 操作。第二个 (normal_commit_branch) 没有。

git tree

问题是,如何在原生 git 命令中强制执行这两种行为? IE。这两个提交之间有什么区别?

最佳答案

这两种 merge 之间的区别只是在提交历史上有所不同(正如您在图中显示的日志)。

让我们用图表来说明。假设 merge 前的提交历史如下:

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

merge 提交(多个 parent ):

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

当你在SmartGit中通过Merge commitdevelop分支 merge 到master分支时(git merge develop),提交历史将是:

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

简单提交(一个父级,“squash”):

它用--squash选项 merge 两个分支,使用的命令是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).

当您在 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/

相关文章:

visual-studio - 源代码控制和错误修复的最佳实践

git - 如何确定 git 提交是否跳过了 pre-hook 检查?

ruby - 贡献 git 包的流程?

node.js - 从 git 安装 NPM 包时是否可以克隆 git 存储库?

git - 同步 TFS 和 GIT

git - 'git merge'具体是如何工作的?

git - 为什么我得到 "git status --porcelain failed"?

json - 如何使用 json diff 合并合并 json 子对象并合并?

GitFlow,压缩和 merge 问题

windows - 哪个分布式版本控制系统具有最好的 Windows GUI 前端?