git Gerrit:将多个提交合并为一个“更改”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18535695/
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
Gerrit: combine multiple commits into one "change"
提问by Nonos
As a git best practice, one should commit frequently, but to review the code you may need to review a patch consisting of multiple commits at once. Is there a way multiple commits can be reviewed and either merged or rejected at once?
作为 git 最佳实践,应该经常提交,但要查看代码,您可能需要一次查看由多个提交组成的补丁。有没有办法可以多个提交并一次合并或拒绝?
采纳答案by Brad
No, Gerrit does not currently support batching commits into one review. However, there are a couple other options.
不,Gerrit 目前不支持将提交批量提交到一个评论中。但是,还有其他一些选择。
At $DAYJOB, my team uses feature branches for larger changes. The smaller commits are reviewed/merged to the feature branch individually, but the feature branch is only merged in once everything is in a good place and all developers are happy.
在 $DAYJOB,我的团队使用功能分支进行更大的更改。较小的提交被单独/合并到功能分支,但只有在一切都处于良好状态并且所有开发人员都满意时才会合并功能分支。
Gerrit also supports topic branches - which are a convenient way to group related commits. They are discussed briefly in the documentation. These commits must still be reviewed/merged individually, but they can be quickly grouped together in the web UI.
Gerrit 还支持主题分支——这是一种对相关提交进行分组的便捷方式。文档中对它们进行了简要讨论。这些提交仍必须单独/合并,但它们可以在 Web UI 中快速组合在一起。
回答by Emil Sit
One thing you can do a squash merge to a temporary branch and then post that change for review.
您可以将壁球合并到临时分支,然后发布该更改以供审核的一件事。
git checkout -b feature
git commit -m "start feature"
...
git commit -m "finish feature"
git checkout -b feature-review master
git merge --squash feature
git commit
Now your feature-review
branch will contain the same diff relative to master
as feature
did but with only a single commit.
现在您的feature-review
分支将包含与master
as feature
did相同的差异,但只有一次提交。
回答by akirillov
If you need to update already posted review requests then you can leverage amend commits:
如果您需要更新已经发布的请求,那么您可以利用修改提交:
git commit --amend -C HEAD
and then push for consequent review.
然后推动后续。
I believe that public commits should be atomic and contain the complete bunch of functionality which you want to contribute. Usually you do not want to share all of your intermediate commits. So squashing commits before review is good idea.
我相信公共提交应该是原子的,并且包含您想要贡献的完整功能。通常你不想共享所有的中间提交。所以在之前压缩提交是个好主意。