Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rebase all commits of a Gerrit review at once without losing +2 votes?

Tags:

git

gerrit

I have a change with several commits, e.g.:

  • last
  • second
  • first

I have received +2 for merging, but unfortunately master has moved, and one of the commits shows as "merge conflict", so I can't submit all commits at once.

However, when I try to rebase locally, the rebase is trivial. And also, if I use Rebase on the web interface, it successfully resolves the conflict.

The problem with rebasing locally however, is that I would lose the +2 votes, and have to annoy reviewers again.

The web interface does conserve my +2 votes, but I haven't found a way to rebase all commits at once: the best I could do was:

  • rebase first on the new master
  • rebase second on top of first with Rebase on parent change
  • and so on until the final commit

If I try to rebase the last commit directly on the web UI, as I would do from the CLI, Gerrit warns me that this would break the relation chain:

Rebase on top of the master branch (breaks relation chain)

which I think means only one commit will go on top of master, and not rebase as I want?

Is there a way to rebase all at once, without losing my +2 votes?

Tested on Gerrit 2.16.2.


People also ask

How do you rebase a Gerrit review?

Just click on "Rebase" button to rebase the change. The behaviour is described in Gerrit Review UI: If the rebase is successful, a new patch set with the rebased commit is created. If the rebase fails, there are conflicts that have to be resolved manually.

Can I rebase multiple times?

Yes, you can rebase more than once. After rebasing, you get a fresh set of commits. These commits are exactly like all other commits and hold no record of having been rebased. The main thing you need to be careful for is the possibility of rebase conflicts.

What does rebase mean in Gerrit?

Rebase a Change. Move a Change. Abandon/Restore a Change. Cherry-Pick changes of a Change. Using Topics.


1 Answers

When you have one change with several patchsets (commits) you don't need to rebase each commit, you just need to rebase the last commit. Actually you're going to submit (integrate/merge) just the last commit not the whole chain. Every time you amend a patchset you create a new commit that replaces the previous one.

If you're confused with this concept it's good to read the Working with Gerrit: An example item in Gerrit documentation.

Answering your question: When you rebase a patchset, Gerrit will treat the +1/+2 votes according to the copyAllScoresOnTrivialRebase configuration of the project. If true, all scores for the label are copied forward when a new patch set is uploaded that is a trivial rebase. There's no difference in how this works if the rebase is made manually and pushed or made using the Web UI. If you're getting a different behavior make sure you're not changing the commit message.

A new patch set is considered as trivial rebase if the commit message is the same as in the previous patch set and if it has the same code delta as the previous patch set.

like image 115
Marcelo Ávila de Oliveira Avatar answered Oct 06 '22 00:10

Marcelo Ávila de Oliveira