It is not possible to set per-commit reviewers, these are applied per push (see gerrit's git-receive-pack manual). Instead of executing git push origin HEAD
or git review
(assuming origin
to be the gerrit remote, and HEAD
the branch you want to push), you can run the following to add two reviewers for all new commits:
git push origin HEAD:refs/for/master%[email protected],[email protected]
That gets applied to all commits which is not what you want. Due to the above limitations, let's change the workflow to push changes first and then set some reviewers.
Since Gerrit distinguishes between Cc
(just send a mail notification) and reviewers (send a mail, but also mark the user as reviewer), I'll modify the commit message as follows:
component: make foo more bar
Foo was not bar enough, this change adds more bar to make foo fit better
in baz.
[email protected]
[email protected]
Change-Id: I4724e283214e0bfbb85a8e3d8db4971618e2609a
Given a number of commits, one can follow the following steps to add separate reviewers for each commit:
- Gather a list of commits IDs (or
Change-Id
s). Example that assumes the master branch as base: git rev-list --reverse origin/master..
- For each commit ID, scan for
R=...
(reviewers) in the commit message. The commit message for a given commit can be found with git show --no-patch --format=%b COMMIT_ID
- If reviewers exist for a commit message, add them with the command
ssh -p 29418 user@host 'gerrit set-reviewers -a [email protected] COMMIT_ID'
(instead of COMMIT_ID
, you can also use the Change-Id
which is I4724e283214e0bfbb85a8e3d8db4971618e2609a
for the example).
To perform the above steps (together with auto-detecting the user, host and port settings), I wrote a Bash script: https://git.lekensteyn.nl/scripts/tree/git/gerrit-add-reviewers
It is recommended to have a .gitreview
file in your repo with a remote that points to a Gerrit instance. Then execute ~/scripts/gerrit-add-reviews origin/master..
from within that git repo to scan commit messages and add reviewers.