Gerrit – How to upload new Patch Set to old commit

Jun 01

We have been struggling to find a way that allows us uploading a new Patch Set to an old commit in Gerrit. Sometimes a commit waits review for couple of days. Even for the same developer who had uploaded other commits. During this time a lot of changes will be approved and merged to the branch. This is not being done based on chronological order, instead it’s related to the priority of the commit. Adding a new Patch Set in such case become a little bit tricky. Re-uploading a new Patch Set even with the same Change-Id produce errors that encourage you to squash your commits.

Note: The Gerrit version used in this article is 2.12.2. You may skip installing the plugin if you already have it in your version.

Installing download-commands plugin

  1. Getting the plugin
  2. You will need to install download-commands plugin. You can check it out and build it or you can download it as a pre-compiled JAR from this site.

  3. Add the JAR to the plugins folder inside Gerrit.
  4. Applying configurations
  5. Then we will need to configure the plugin. This could be done by adding the following to etc/gerrit.config file:

    Those are my configurations however you can find a full list in the documentation page.

  6. Restart Gerrit

Now we have installed the plugin, you will find a new items in the download menu (top right corner).

Gerrit after installing download-commands (A step to upload new Patch Set)

Gerrit after installing download-commands

Steps to upload a new Patch Set

  1. Copy the proper Checkout link from the newly added section. This could be ssh, HTTP or whatever you are using.
  2. Run the copied command into your Git repository. This will create a branch with no name (DETACHED HEAD)
  3. Give that branch a new name.
  4. Do the changes you want.
  5. Changes might include rebasing your code on top of the HEAD.

  6. Run the following if there are any changes to the files
  7. Send the changes again to Gerrit

You will find a new Patch Set on Gerrit waiting for review and that’s it.

Leave a Reply