Skip to content

[archived] Gerrit: use cases

Matthieu Baerts edited this page Jul 14, 2019 · 1 revision

Note: Now that the new architecture code has been added in our repo, we are back to the patches sent via e-mails, with short iterations.

Typical use-cases / workflow

The workflow is basically the same as before but instead of using git send-email, git review will be used.

New patch-set

You are starting a new feature:

git checkout -b my_branch for-review
(...)                 # work here
git add -u <...>
git commit -sm "foo"  # Change-Id has been added
(...)                 # create more commits if needed
git review for-review # new Change created, by default the target branch is `master` if you didn't set a .gitreview file

Update an existing one

You previously send a first version of your patch-set but you now want to update these patches:

git checkout my_branch
git commit --amend    # or `git rebase -i <...>` as before
git review for-review # Changes have been updated, by default the target branch is `master` if you didn't set a .gitreview file

Download a change

To download a change created or updated by someone else, e.g. the ID 436386:

git review -d 436386

Rebase and rework at the same time

If you need to rebase your work and send a new version, ideally and to help reviewers, it is better to do that in two phases not to compare two versions with two different bases:

git checkout my_branch

# step 1: rebasing the work
git rebase origin/for-review
git review --work-in-progress  # change will be marked as WIP and "rebased"

# step 2: doing extra modifications
git commit --amend             # or `git rebase -i <...>` as before
git review --ready             # WIP mark will be removed

New patch-set on top of someone else's changes

There are two cases here: either these other changes are already in our Gerrit or changes have been published somewhere else (e.g. RFC for net-next)

On top of someone else's changes already in Gerrit

Simply create your new commits like you would on top of for-review but download the other changes first:

git review -d 436386  # instead of something like: git checkout -b my_branch for-review
(...)                 # work here
git commit -s         # create more commits if needed
git review for-review # new Change created on top of Change 436386, by default the target branch is `master` if you didn't set a .gitreview file

On top of other RFC changes (not in Gerrit)

The easiest way is to also add these other commits in your development branch you publish in Gerrit:

git am <patch>                 # or cherry-pick or pull ...
git commit --amend --no-edit   # to add the Change-Id for Gerrit
(...)                 # work here
git commit -s         # create more commits if needed
git review for-review # new Changes created including the ones from other people

Note: if you have a bunch of commits where the Change-Id is missing, you can use this command:

cp .git/hooks/commit-msg /tmp
git filter-branch -f --msg-filter 'git log -1 --pretty=%B $GIT_COMMIT > msg.txt; /tmp/commit-msg msg.txt; cat msg.txt; rm msg.txt' <LAST_COMMIT_IN_A_PUBLISHED_BRANCH>..HEAD

Helpful Hints

Note: it is also possible to use the --private mode with Gerrit