Nonos
Nonos

Reputation: 2518

Gerrit: combine multiple commits into one "change"

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?

Upvotes: 45

Views: 39114

Answers (3)

Brad
Brad

Reputation: 5532

No, Gerrit does not currently support batching commits into one review. However, there are a couple other options.

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.

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.

Upvotes: 20

akirillov
akirillov

Reputation: 77

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.

Upvotes: 0

Emil Sit
Emil Sit

Reputation: 23542

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.

Upvotes: 39

Related Questions