git `--squash` 和 `--no-ff --no-commit` 之间有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11983749/
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
What are the differences between `--squash` and `--no-ff --no-commit`?
提问by Tobias Kienzler
Which one should one use to hide microcommits?
应该使用哪一个来隐藏微提交?
Is the only difference between git merge --squash
and git merge --no-ff --no-commit
the denial of the other parents?
是其他父母之间的唯一区别git merge --squash
和git merge --no-ff --no-commit
否认吗?
回答by Yasushi Shoji
The differences
差异
These options exists for separate purposes. Your repository ends up differently.
这些选项存在于不同的目的。您的存储库以不同的方式结束。
Let's suppose that your repository is like this after you are done developing on the topic branch:
假设您在主题分支上完成开发后,您的存储库是这样的:
--squash
--squash
If you checkout master and then git merge --squash topic; git commit -m topic
, you get this:
如果你结帐 master 然后git merge --squash topic; git commit -m topic
,你会得到这个:
--no-ff --no-commit
--no-ff --no-commit
Instead, if you do git merge --no-ff --no-commit; git commit -m topic
, you get this:
相反,如果你这样做git merge --no-ff --no-commit; git commit -m topic
,你会得到这个:
Hiding micro-commits
隐藏微提交
If you really want to hide (I mean deletefrom your repository) your micro-commits, use --squash
. Because, as you can see in the above images, you are not really hiding your micro-commits if you do not squash. Moreover, you do not usually push your topic branches to the world. Topic branches are for topic to get mature.
如果您真的想隐藏(我的意思是从您的存储库中删除)您的微提交,请使用--squash
. 因为,正如你在上面的图片中看到的,如果你不压缩,你并没有真正隐藏你的微提交。此外,您通常不会将您的主题分支推向全世界。主题分支是为了让主题变得成熟。
If you want your history to have all your micro-commits, but leave them in another line of development (the green line in the above images), use --no-ff --no-commit
. But please remember that a) this is not a branch, and b) does not really mean anything in Git because it is just another parent of your commit.
如果您希望历史记录包含所有微提交,但将它们留在另一条开发线中(上图中的绿线),请使用--no-ff --no-commit
. 但是请记住 a) 这不是一个分支,并且 b) 在 Git 中并不真正意味着什么,因为它只是您提交的另一个父级。
Please refer to Git Branching - What a Branch Isif you really want to understand.
如果您真的想了解,请参阅Git 分支 - 分支是什么。