Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gerrit: combine multiple commits into one "change"

Tags:

git

gerrit

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?

like image 677
Nonos Avatar asked Aug 30 '13 14:08

Nonos


People also ask

How do I merge two Gerrit commits?

The default way is to correct it locally (i.e. combine both commits using either git rebase --interactive or git reset --soft HEAD~1; git commit ). Then push the combined commit. Finally, abandon the now obsolete (and marked as OUTDATED) second commit using the gui/website.

How do I combine multiple commits in a commit?

To "squash" in Git means to combine multiple commits into one. You can do this at any point in time (by using Git's "Interactive Rebase" feature), though it is most often done when merging branches. Please note that there is no such thing as a stand-alone git squash command.


2 Answers

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.

like image 65
Emil Sit Avatar answered Oct 02 '22 04:10

Emil Sit


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.

like image 20
Brad Avatar answered Oct 02 '22 04:10

Brad