为什么 `git merge <branch> --squash` 不提交?
Why doesn't `git merge <branch> --squash` make a commit?
进行正常合并时,例如git merge <branch>
、git
创建合并提交并将当前分支的 HEAD
更新为该提交。
进行壁球合并时,例如git merge <branch> --squash
,但是,它没有提交,说(在干净的合并上):
Squash commit -- not updating HEAD
Automatic merge went well; stopped before committing as requested
这背后的原理是什么?对我来说,这似乎是普通合并和挤压合并之间的意外差异。如果正常合并和挤压合并之间的仅区别是挤压合并挤压提交,那对我来说会更直观。
What's the rationale behind this?
草稿合并提交消息将包含来自其他分支的所有压缩消息。像这样:
Squashed commit of the following:
commit 2fb77b77f813501ae2c8159e7bf751c216572a57
Author: Your Name <you@example.com>
Date: Tue May 22 22:47:50 2018 +0200
Drop baz
commit 894f1ef07af29d25c4716dce9db4402032f854d4
Author: Your Name <you@example.com>
Date: Tue May 22 22:47:39 2018 +0200
Fix bar
commit 7f60998ab1949e9e8db9229f9ef9e7c0333cd04f
Author: Your Name <you@example.com>
Date: Tue May 22 22:47:19 2018 +0200
Add foo
通常,您会希望在提交之前自定义该消息。
如果您对默认消息感到满意,您可以这样做:
git merge <branch> --squash && git commit --no-edit
这种为什么的问题确实必须首先发送给编写命令的人;只有他们真正知道。
底层实现是惰性的:它通过与常规合并相同的代码路径但跳过写入文件 MERGE_HEAD
,然后提前退出以避免通过将进行合并提交的代码。
如果您使用 --no-commit
选项,代码将经过几乎相同的路径。事实上,这个的控制变量是 option_commit
,设置 --squash
清除 option_commit
就好像你 运行 和 --no-commit
.
如果--squash
没有清除option_commit
,看起来现有路径会抱怨自动合并失败。所以可能只是懒惰。
好吧,如果你像我一样,问题是你已经将该分支合并到 master 中,却忘记了你已经这样做了。它没有更新,因为更改和母版相同。
希望这个答案能帮助其他人比我浪费更少的时间。
进行正常合并时,例如git merge <branch>
、git
创建合并提交并将当前分支的 HEAD
更新为该提交。
进行壁球合并时,例如git merge <branch> --squash
,但是,它没有提交,说(在干净的合并上):
Squash commit -- not updating HEAD
Automatic merge went well; stopped before committing as requested
这背后的原理是什么?对我来说,这似乎是普通合并和挤压合并之间的意外差异。如果正常合并和挤压合并之间的仅区别是挤压合并挤压提交,那对我来说会更直观。
What's the rationale behind this?
草稿合并提交消息将包含来自其他分支的所有压缩消息。像这样:
Squashed commit of the following:
commit 2fb77b77f813501ae2c8159e7bf751c216572a57
Author: Your Name <you@example.com>
Date: Tue May 22 22:47:50 2018 +0200
Drop baz
commit 894f1ef07af29d25c4716dce9db4402032f854d4
Author: Your Name <you@example.com>
Date: Tue May 22 22:47:39 2018 +0200
Fix bar
commit 7f60998ab1949e9e8db9229f9ef9e7c0333cd04f
Author: Your Name <you@example.com>
Date: Tue May 22 22:47:19 2018 +0200
Add foo
通常,您会希望在提交之前自定义该消息。
如果您对默认消息感到满意,您可以这样做:
git merge <branch> --squash && git commit --no-edit
这种为什么的问题确实必须首先发送给编写命令的人;只有他们真正知道。
底层实现是惰性的:它通过与常规合并相同的代码路径但跳过写入文件 MERGE_HEAD
,然后提前退出以避免通过将进行合并提交的代码。
如果您使用 --no-commit
选项,代码将经过几乎相同的路径。事实上,这个的控制变量是 option_commit
,设置 --squash
清除 option_commit
就好像你 运行 和 --no-commit
.
如果--squash
没有清除option_commit
,看起来现有路径会抱怨自动合并失败。所以可能只是懒惰。
好吧,如果你像我一样,问题是你已经将该分支合并到 master 中,却忘记了你已经这样做了。它没有更新,因为更改和母版相同。
希望这个答案能帮助其他人比我浪费更少的时间。