Skip to main content
Jump to: navigation, search


Revision as of 11:09, 18 May 2012 by (Talk | contribs) (Verifying Changes on Hudson using Gerrit Trigger Pluggin)

From TFM: Gerrit is a web based code review system, facilitating online code reviews for projects using the Git version control system. It is not available for CVS or SVN. For more information about Gerrit, please see

Using Gerrit hosted at

Enabling Gerrit for your Project

  • File a bug and specify for which project you'd like to enable Gerrit
  • Ask your Project Lead to +1 the request
  • Choose one of the two options:
    • I want project committers use Gerrit code review exclusively for my project. Everything must be reviewed -- no direct access to the main repo should be available.
    • I want project committers to be able to bypass the Gerrit code review system and push changes directly to the git repo.

User Account

  • In order to contribute you need an Eclipse user account . If you are an Eclipse committer you already have one.
  • Confirm you agree to the Terms of Service by completing the Individual Contributor agreement.


Gerrit Web UI

Logon to the Gerrit Web UI at using the email address you registered with your Eclipse (and Bugzilla) account and your Eclipse password.

Git over SSH

When accessing Gerrit over SSH from git or EGit use the username displayed here and upload your public SSH key to Gerrit here.

Gerrit SSH URl:
Gerrit SSH service versus SSH shell access
Gerrit's SSH service listens on port 29418 and isn't linked to the public keys on used for SSH shell access on port 22

Git over HTTPS

When accessing Gerrit over HTTPS from git or EGit use username and HTTP password displayed here

Gerrit HTTPS URl:

SSH Keys

  • Add one or more public SSH keys to Gerrit here.
  • If you are absolutely certain you do not have keys already, you must create a public and private pair of SSH keys. It is strongly recommended that you use a passphrase.
  • Generating SSH key pair on command line
ssh-keygen -t rsa -C ""
  • Execute SSH once to accept the host key (or copy it from the registration web page)
ssh -p 29418

Doing Code Reviews with Gerrit

Using Gerrit with the git command line:

  • Upload your patch from Git to the target project:
git push ssh:// HEAD:refs/for/master

Adding a dedicated remote

Since git can have multiple remotes, you can define one to be used to refer to Gerrit to save typing. Inside a previously checked-out repository you can run:

cd path/to/project
git config ssh://
git config HEAD:refs/for/master

You can now submit review requests from either repository using:

git push review

Using Gerrit with EGit:

Eclipse will look for your private key in the SSH2 Home location specified in the General>Network Connections>SSH2 Preference Page. If your id_rsa private key makes use of the AES-128-CBC algorithm (view the file as text to confirm), Eclipse will need at least com.jcraft.jsch 0.1.44 to make use of it.

  • Clone the repository and use the last page of the Clone Wizard to configure pushing to the code review queue.
  • Alternative approach adding a review remote in the Git Repositories view:
    • From the appropriate Remotes node, create a New Remote and choose to Configure for Push. A unique name should be chosen, review is suggested.
    • Change the main URI or Add a Push URI (your Gerrit user name must be used here)
    • In the Ref mapping section, add a RefSpec specification of HEAD:refs/for/master
    • Changes committed to your local clone can now be pushed to Gerrit using the review Remote. You will be prompted for your private key's passphrase if Eclipse is looking for it in the right place.

Gerrit Code Review Cheatsheet

Install the commit-msg hook in your repository

scp -p -P 29418 .git/hooks/

This will ask for a password. It is the password that you have to generate in the SSH Keys section of settings in your Gerrit account.

You can alternatively download the file or use curl to install it via https:

# if you are behind a proxy you may need
export https_proxy=https://<proxy-host>[:<proxy-port>]
curl > .git/hooks/commit-msg

The hook helps append a Change-Id to your commit message.

EGit can also generate the Change-Id and can also be configured to automatically include it.

To create a new change

git push ssh:// HEAD:refs/for/master

Or, if you've followed the instructions on #Adding_a_remote you can simply do:

git push review

Since the current repository has the right definition for 'review', you won't need to remember the canonical push URL

To update an existing change with a new commit

git push ssh:// HEAD:refs/for/master

This works because Gerrit links the new commit to the prior change based upon the Change-Id footer in the commit message. (This is automatically generated by the commit-msg hook you installed above.) If you refuse to use the commit-msg hook, or don't have a Change-Id footer, you should read the Gerrit documentation on change-id lines and replacing changes.

Note: To be picked up by Gerrit, a Change-Id line must be in the bottom portion (last paragraph) of a commit message, and may be mixed together with the Signed-off-by, Acked-by, or other such footers. So if your Change-Id line is ignored it's probably not in the last paragraph :).

To compare bulk diffs using Git

Since each Gerrit review patchset actually commits its own tree, you can pull out the trees and compare them.

If you've got a large changeset, and you want to be able to do diffs between them via (command line) git instead of browsing on the web, then you can fetch the individual changes and then perform a diff. For example, shows the 'download' section for each patchset. In this case, it looks like:

Performing a git pull will both get the bits and merge them into your tree, which won't do what you want for comparison. So, in order to get the bits (but not merge), you need to do a git fetch instead. Let's say we want to diff the last two patches against each other rather than reviewing the entire patchset again:

git fetch ssh:// refs/changes/02/2/3
git fetch ssh:// refs/changes/02/2/4

git diff d14cc645655683ba3e30a35833fb2282142e898f 43de8d385b614c72fd796e17da75d381f6e0cc25

# or git diff d14cc6 43de8d

If you're doing this from within an already checked out project, you can do git fetch origin (or any other remote name in .git/config}.

Git fetched data will stay around in your repository, but will be 'orphaned' if no references point to it. To clean up, you can run git gc or wait until this happens automatically.

To approve a change

  • Click on Publish Comments
  • Vote with the radio buttons

To add a reviewer

Once you've pushed your commit to Gerrit for review, you can go to the web page ( and see your changes. By clicking on the review, there's an option to add a reviewer by e-mail address; they'll then be sent a message indicating that they'd like your review on the item.

Code Review

The code review category indicates your opinion on the quality of the code, and how well it fits within the purpose of the existing surrounding code. A +2 vote from any committer is required before submission can occur. A -2 vote from any committer will block submission.

IP Review

Follow the rules given in Handling Git Contributions received via Gerrit. Committers should mark contributions "IP Clean +1" only if they are complying to these rules.

Verifying Changes on Hudson using Gerrit Trigger Plugin

You may use the Jenkins Gerrit Trigger Plugin installed on sandbox Hudson in order to run a Hudson job to verify each new patchset uploaded to Gerrit for code review. Hudson will then also vote on these changes using the "Verify" voting category.



In order to setup a verification build job file a bug in Bugzilla on "Eclipse Foundation > Community" using component "Hudson sandbox" and ask the webmaster to create a new build job on sandbox Hudson. Then configure the new job following the description given on the plugin's home page.

The configuration sections for the Git plugin and the Gerrit trigger plugin of the verification job used by the JGit project may serve as an example.

Configuration of Git plugin:

  1. Under Source Code Management select Git. Click on Advanced and change the Choosing Strategy to Gerrit Trigger.
  2. Follow the settings depicted below:


Configuration of Gerrit trigger plugin:


Back to the top