Skip to content

Instantly share code, notes, and snippets.

@afbjorklund
Last active August 29, 2015 14:21
Show Gist options
  • Save afbjorklund/b120164312c7353de549 to your computer and use it in GitHub Desktop.
Save afbjorklund/b120164312c7353de549 to your computer and use it in GitHub Desktop.
git:review

Git: Gerrit Code Review

Review (notes)

refs/notes/review is a special reference that Gerrit creates on repositories to store information about code reviews.

When a repository is cloned from Gerrit, the refs/notes/review reference is not included by default. It has to be manually fetched:

$ git fetch origin refs/notes/review:refs/notes/review

It is also possible to configure git to always fetch refs/notes/review:

$ git config --add remote.origin.fetch refs/notes/review:refs/notes/review
$ git fetch

This will add the refs/notes/review to the default refspec in .git/config:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	fetch = +refs/notes/review:refs/notes/review
	url = https://gerrit.googlesource.com/gerrit

Note that the Gerrit server will need to have the "reviewnotes" plugin installed, for the extra ref to be available for fetching.

Viewing notes

When refs/notes/review is fetched on a repository, the Gerrit review information can be included in the git log output:

$ git log --pretty=fuller --notes=review
commit 8265bdba1fec42864af02c3081576118b69bad60
Author:     Saša Živkov <sasa.zivkov@sap.com>
AuthorDate: Tue Jan 27 15:32:25 2015 +0100
Commit:     Saša Živkov <sasa.zivkov@sap.com>
CommitDate: Tue Jan 27 15:32:25 2015 +0100

    Update version to 2.10
    
    Change-Id: I2795796ae77d240001fe5c789fe1aeae5fc34d56

Notes (review):
    Code-Review+2: Saša Živkov <zivkov@gmail.com>
    Verified+1: Saša Živkov <zivkov@gmail.com>
    Submitted-by: Saša Živkov <zivkov@gmail.com>
    Submitted-at: Tue, 27 Jan 2015 15:31:27 +0000
    Reviewed-on: https://gerrit-review.googlesource.com/63730
    Project: gerrit
    Branch: refs/heads/stable-2.10

With the patched git (review), you can use something like git log --pretty=fullest to view it in a more natural format:

$ git --version
git version 2.4.0.1.gf6cd9a3
$ git log --pretty=fullest
commit 8265bdba1fec42864af02c3081576118b69bad60
Author:     Saša Živkov <sasa.zivkov@sap.com>
AuthorDate: Tue Jan 27 15:32:25 2015 +0100
Commit:     Saša Živkov <sasa.zivkov@sap.com>
CommitDate: Tue Jan 27 15:32:25 2015 +0100
Submit:     Saša Živkov <zivkov@gmail.com>
SubmitDate: Tue Jan 27 15:31:27 2015 +0000

    Update version to 2.10
    
    Change-Id: I2795796ae77d240001fe5c789fe1aeae5fc34d56

All the regular date formatting characters available to the author and committer dates are also available to the submitted:

  • %Sd: submitted date (format respects --date= option)
  • %SD: submitted date, RFC2822 style
  • %Sr: submitted date, relative
  • %St: submitted date, UNIX timestamp
  • %Si: submitted date, ISO 8601-like format
  • %SI: submitted date, strict ISO 8601 format

The "review" patch for git can be found by doing a Compare in this branch: https://github.com/itension/git/tree/review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment