- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
谁能告诉我这两个命令有什么区别:
git merge --squash
和
git merge --no-ff
最佳答案
我认为你的问题有点误会。 --no-ff
和 --squash
不是对立的,而是略有不同的操作。阅读时请记住这一点。
help page for merge以下是关于 --squash
的内容:
--squash
and--no-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 or move the HEAD, nor 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).
With --no-squash perform the merge and commit the result. This option can be used to override --squash.
这有点令人困惑,并且需要一些关于 git
内部结构的知识。首先,我们需要了解常规提交和 merge 提交之间的区别。常规提交有一个父级,并且只是一个应用于它之前的提交的变更集:
A --> B --> C
merge 提交有多个父级,它是树中的一个位置,您将两个或多个沿袭放在一起:
A --> B --> F
/
C --> D - /
看看 A
、B
、C
和 D
是常规提交,但是 F
是 merge 提交,因为它有多个父级(B
和 D
)?这就是 git merge --no-ff
会产生的结果。它强制 Git 创建一个 merge 提交以将两个历史放在一起。
git merge --squash
会做一些不同的事情。它会阻止 Git 创建 merge 提交,但仍会提取 C
和 D
所做的更改,因此您的树看起来像这样:
A --> B --> F'
C --> D
F'
包含 C
和 D
所做的更改,但没有迹象表明您在存储库中 merge 了两棵树。
--no-ff
是一个略有不同的操作。它会强制 Git 创建一个 merge 提交,即使它并不是真正必要的。作为引用,以下是手册中关于 --no-ff
和 --ff-only
的相反内容:
--no-ff
Create a merge commit even when the merge resolves as a fast-forward.
--ff-only
Refuse to merge and exit with a non-zero status unless the current HEAD is already up-to-date or the merge can be resolved as a fast-forward.
要理解,最好看一个例子:
A --> B --> C --> D --> E
| |
'master' 'topic'
如果您有这棵树,在主分支上,并运行 git merge
,Git 将执行所谓的“快进” merge 。由于这两个历史之间没有分歧,Git 可以将 master
分支向上移动到 topic
所在的位置,而不做任何有趣的事情。它看起来像这样:
A --> B --> C --> D --> E
|
'topic'
'master'
topic 和 master 都指向同一个分支。现在,某些工作流程规则要求您在每次 merge 回 master
时创建 merge 提交。这样可以保留分支机构的历史记录。你会得到关于应该如何完成的任何一种争论,但我不会在这里讨论这些。
如果你在同一棵树上使用 git merge --no-ff
,它会强制 git 创建一个 merge 提交,给你一个像这样的树:
'master'
|
A --> B -------------> F
\ /
C --> D --> E
|
'topic'
其中 F
是新的 merge 提交 --no-ff
强制 Git 创建。
关于Git 压缩和 merge ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23616706/
我从一个 Mercurial 存储库开始,它有多个我试图 merge 到其中的子存储库,就好像它们一直是主存储库的一部分一样。它们从一开始就不应该是子存储库。 我整理了一个将旧历史转换为单个存储库的过
假设我有一个主线分支和一个功能分支。我已经多次将主线分支 merge 到功能分支中,但只有少数非常小的 merge 冲突。我想清理历史,以便最后只有一个 merge 。执行此操作的最佳方法是什么? 最
首先我使用heapq.merge创建了a&b的两个结果,但是在mergea&b之后,我发现a的列表是空的。 >>> a=merge([1,2],[3,4]) >>> b=merge([4,5],[6,
我和我的团队正在使用远离主轨道 (origin/dev) 的远程分支 (origin/our_feature_branch) 开发一项功能。 Gerrit用于审查等。 使用 git merge ori
这个问题在这里已经有了答案: Is there a way to merge with Strategy "ours" without producing a new commit? (1 个回答)
GitLab 无法自动 merge 请求。所有 merge 请求都会收到消息“此 merge 请求包含必须解决的 merge 冲突。您可以在命令行上手动尝试” 消息似乎不正确,我通过使用“git br
git 有没有办法在不 merge 文件的情况下 merge 两个分支?换句话说就是绘制 merge 箭头。 假设我有分支 A 和 B。我需要将分支 B merge 到 A,但不需要 B 中的所有更改
我想使用提供 git 集成的流行的开源问题跟踪器 (Redmine)。不幸的是,跟踪器中的每个项目只能与一个 git repo 相关联。在跟踪器中创建多个项目不是我理想的设置。 考虑到这一点,我尝试使
在我们的存储库中,我们遵循基于 git-flow 的工作流程。我们有一个已完成的发布(安装在生产环境中),因此发布分支已 merge 到主分支中。 B---C---D---E [release
git merge 命令有一个执行快进 merge 的选项,但这不是我想要的,因为如果它不能执行快进 merge ,它会使用普通 merge . 是否有一个 git 命令仅执行快进 merge (从跟
尝试合并 TFS2008 时出现此错误。源分支或目标分支上都没有挂起的更改。 TF14083: The item {0} has a pending merge from the current me
为了更好地理解这些操作,我想知道 github 或 gitlab 到底是如何 merge 这些请求的。当压缩、 rebase 、 merge ......时详细执行哪些 git 命令? 最佳答案 PR
为了更好地理解这些操作,我想知道 github 或 gitlab 到底是如何 merge 这些请求的。当压缩、 rebase 、 merge ......时详细执行哪些 git 命令? 最佳答案 PR
我试图将提交的一部分从默认分支(不是所有文件和其他文件的部分) merge 到一个命名分支。我试过 graft ,但它只需要整个提交,而没有给我选择的机会。这将如何完成? 例子: A---B---C-
我正在进行 merge ,此时我已准备好提交,但我在 TortoiseHg 中的提交对话框显示许多文件已修改,但是当我与 parent 进行比较时,它说所有文件都是二进制相等的。 我没有也从未有过 e
我已经尝试了以下几种变体,但我仍然遇到错误。有什么办法可以解决这个问题。 DB2 10.1(DB2 for z/OS V10) 对于以下 MERGE INTO TRGT t USING SRC s O
我的数据库模型有用户和 MAC 地址。一个用户可以有多个MAC地址,但一个MAC只能属于一个用户。如果某个用户设置了他的 MAC,并且该 MAC 已经链接到另一个用户,则现有关系将被删除,并在新所有者
假设我有一个新功能,所以我创建了一个新分支。这个分支是一个会持续很长时间的副项目,所以我最终将 master merge 回它以使其保持最新状态。这已经发生了 50 次,因为我一直在更新它并消除该功能
过去几个小时我在 Mercurial 中进行了一次巨大的 merge 。 merge 131 个文件后,我的 merge 工具 meld 崩溃,显示 python 回溯。在尝试退出 meld 时,我无
我有一个关于 git merge 的问题。假设我的存储库中有两个分支(本地和远程):master 和 test。当我在测试分支上工作时,主分支被其他人更新了。在终端中,我写: git checkout
我是一名优秀的程序员,十分优秀!