git-review is a command line tool helps submit code to Gerrit for review.
You need to install python (python3 is preferred) in advance. It is also suggested to install git-review with version > 1.28.0.
# Install pip
$ sudo apt-get install python3-pip
$ sudo easy_install pip
# Install git-review
$ sudo pip install git-review
Enter the root dir of git repos.
# Default name use for git remote
$ git config gitreview.remote origin
# Default username used to access the repository
$ git config gitreview.username "USER_NAME"
# Submit changes to the currently-tracked branch by default
$ git config gitreview.track true
Run the repo setup commands.
$ git review -s
(Optional) Set default branch to commit.
$ git config gitreview.defaultbranch BRANCH_NAME
Gerrit treats each review as a change
, and use Change-Id
to identify commits that belong to the same review.
This allows a second commit to be updated to the same change to address reviewer’s comment.
We can setup a hook to generate change-id automatically after commit.
$ scp -p -P 29418 user_name@your.gerrit.server:hooks/commit-msg /path/to/local/git/repos/.git/hooks/
$ chmod u+x /path/to/local/git/repos/.git/hooks/commit-msg
Here lists some frequently used commands.
Some Gerrit projects may require commits to be submitted with a sign-off.
$ git commit -s
Submit commit to a branch. If branch is net set, push to default branch.
$ git review BRANCH_NAME
Submit commit to a branch and add reviewers.
# mail list are seperated by whitespace
$ git review BRANCH_NAME --reviewers mail1 mail2
Submit commit to a branch and add topic
$ git review BRANCH_NAME -t "TOPIC"
Submit commit as a draft
$ git review BRANCH_NAME -D
If you have created a branch for that change, switch to that branch. Otherwise, fetch the change from Gerrit.
$ git review CHANGE_ID
List changes waiting for review
$ git review -l
Fetch a change from Gerrit for revirw.
$ git review -d CHANGE_ID
Fetch a specific patchset of a change.
$ git review -d CHANGE_ID,PATCHSET_NUM
Fetch and compare two patchsets of a change. (This actually creates two branches for each patchset.)
$ git review -m CHANGE_ID,PATCHSET_A-PATCHSET_B
# Example
$ git review -m 1000,1-3
My best practice is that: creating a branch at local for preparing submission and deleting that branch after code was reviewed and merged.
Creating a local branch in advance brings convinence when:
Gerrit
Git
Written on
January
26th,
2021
by
Borting