Git merge --squash 和 --no-commit 的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9599411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:08:48  来源:igfitidea点击:

Differences between Git merge --squash and --no-commit

gitmergesquash

提问by quaylar

As the title says, I am not really clear about the differences between a git merge --squashand a git merge --no-commit.

正如标题所说,我不太清楚 agit merge --squash和 a之间的区别git merge --no-commit

As far as I understand the help page for git merge, both commands would leave me in an updated working-tree, where it is still possible to edit and then to do a final commit (or multiple commits).

据我了解的帮助页面git merge,这两个命令都会让我处于更新的工作树中,在那里仍然可以进行编辑,然后进行最终提交(或多次提交)。

Could someone clarify the differences of those 2 options? When would I use one instead of the other?

有人可以澄清这两个选项的区别吗?我什么时候会使用一个而不是另一个?

回答by ralphtheninja

git merge --no-commit

This is just like a normal merge but doesn't create a merge-commit. This commit will be a merge commit: when you look at the history, your commit will appear as a normal merge.

这就像普通的合并,但不会创建合并提交。此提交将是合并提交:当您查看历史记录时,您的提交将显示为正常合并。

git merge --squash

This will merge the changes into your working tree without creating a merge commit. When you commit the merged changes, it will look like a new "normal" commit on your branch: without a merge commit in the history. It's almost like you did a cherry-pick on all the merged changes.

这会将更改合并到您的工作树中,而无需创建合并提交。当您提交合并的更改时,它看起来像您分支上的一个新的“正常”提交:历史记录中没有合并提交。这几乎就像您对所有合并的更改进行了挑选。