choeger
choeger

Reputation: 3567

Rebase a gerrit-reviewed patchset

In a process where each change is reviewed with gerrit, I have local branches for each ticket (e.g. trac-0815). Every now and then, I need to rebase my changes before they can be applied to the main branch.

When done on my local branch, I can follow this workflow:

  1. checkout trac-0815
  2. fetch
  3. rebase
  4. push to gerrit

This creates a new patch set in gerrit. The information that this is only a rebase is lost, however.

Alternatively, gerrit offers a "rebase" button. This also creates a new patch set, but immediately adds the information about a rebase, e.g. "Patch Set 2: Patch Set 1 was rebased". Obviously, this is preferable. But how do I now sync my local branches? When I do:

  1. checkout trac-0815
  2. pull from gerrit

I get a merge commit in my history, which is something, I'd like to avoid. In principle, I could rebase the local branch separately, but that appears to be tedious and error prone. What I'd like to have is a pull command that overwrites the last commit.

Upvotes: 2

Views: 4481

Answers (1)

A easy way to do that is to delete your local branch and recreate it pointing to the Gerrit commit:

  1. git fetch https://GERRIT-SERVER/a/ refs/changes/X/Y/Z && git checkout FETCH_HEAD
  2. git branch -D trac-0815
  3. git checkout -b trac-0815

The #1 can be copied from Gerrit > Change > Download > Checkout

Upvotes: 3

Related Questions