ci.csn.khai.edu

CI-infrastructure of Computer Systems and Networks Department

How to checkout on specific patch set in Gerrit Code Review

When you are working with Gerrit Code Review there is a need not only to get access to project changes that is waiting for “review”, but also to switch to a specific patch set. There are several approaches. Let’s focus on one of them, which is quite simple and verbose.

Note: Before the start, make sure that all necessary software (git, git-review) is installed and configured properly.

  1. Clone the required project (git clone):

    $ git clone ssh://[email protected]:29418/cicsnkhaiedu-dev/sandbox
    Cloning into 'sandbox'...
    remote: Counting objects: 6, done
    remote: Finding sources: 100% (6/6)
    remote: Total 6 (delta 0), reused 6 (delta 0)
    Receiving objects: 100% (6/6), 671 bytes | 0 bytes/s, done.
    Checking connectivity... done.
    

    Clone project gerrit

  2. Go to the directory with the project:

    $ cd sandbox
    
  3. Gerrit Code Review allows you to get the information about all changes that have ever existed in the sandbox project.

    get all changes for project in gerrit code review

  4. Select the required changes (the proposed patch set). In our case, this is a project with the Subject `Add small changes to README.md file’

  5. Copy the number that follows /c/ in the url field of the web browser (in our case this is 2). This number indicates the Change Set in the project:

    Url path to project changes in gerrit

  6. Run git review command with the -d option (download) and specify the change number in the project - “branch”:

    $ git review -d 2
    Creating a git remote called "gerrit" that maps to:
         ssh://[email protected]:29418/cicsnkhaiedu-dev/sandbox
    Downloading refs/changes/02/2/4 from gerrit
    Switched to branch "review/vitalii_kulanov/2"
    

    After executing this command, a separate branch review/vitalii_kulanov/2 will be created, and you will be automatically switched to it.

    Note: To check which “branch” you are on or see all available “branches” for your repository, execute the git branch command (you can use --all option):

    $ git branch
      master
    * review/vitalii_kulanov/2
    $ git branch --all
      master
    * review/vitalii_kulanov/2
      remotes/gerrit/master
      remotes/origin/HEAD -> origin/master
      remotes/origin/master
    

    Please note, that now we have just downloaded and switched to the last suggested changes in the patch (last patch set). Also it is possible to switch between certain patch sets.

  7. The list of available Patch Sets is shown in Gerrit Code Review interface:

    List of patch sets in gerrit

  8. Note, when you select a specific Patch Set, the url path will be changed too. It includes the change number in the project (Change Set) and the Patch Set number:

    Url path to specific patch set in gerrit

  9. For switching to a specific Patch Set within the Change Set run the git review command with the -d option, specify Change number in the project and the number of the required Patch Set (comma separated):

    $ git review -d 2,3
    Downloading refs/changes/02/2/3 from gerrit
    Switched to branch "review/vitalii_kulanov/2-patch3"
    

    review/vitalii_kulanov/2-patch3 branch will be automatically created and you will be switched to it.

    Check the list of “branches” with git branch command:

    $ git branch
      master
      review/vitalii_kulanov/2
    * review/vitalii_kulanov/2-patch3
    

    Command git diff checks the current changes (in relation to the” origin/master “branch):

    $ git diff origin/master
    diff --git a/README.md b/README.md
    index dad16bd..f48e1e1 100644
    --- a/README.md
    +++ b/README.md
    @@ -1 +1,7 @@
    # Hello from sandbox
    +
    +This is a change
    +
    +And even more changes
    +
    +Last one
    
  10. Make all the necessary changes to the current Patch Set and send these changes on “review”. The sequence of git commands should be the following:

   $ git add .
   $ git commit --amend
   $ git review

Note: You should always use the git commit command with the --amend option if you make changes to the existing changes (Change Set) of the appropriate Patch Set.