gitgerritgit-review

gerrit - checkout change-set by "number"


I can retrieve a list of drafts for the current owner like this:

ssh -p 29418 gerritServer.com gerrit query projectName owner:self is:draft

In the output is a "number" field which the git-review tool uses as input for it's git-review -d command.

I'm trying to come up with a workflow that doesn't rely on git-review. How do you checkout a change-set by using this "number" field?


Solution

  • The number you're talking about is the change number, a number that's incremented by one for each change created on the server. The change number is part of the Git reference where the patch set it stored. The reference is built up like this:

    refs/changes/<changenum modulo 100>/<changenum>/<patchsetnum>
    

    So, the ref for patch set 3 of change 2704 becomes refs/changes/04/2704/3. If you're running gerrit query the result not only includes the change number but also the ref so there's no need to figure it out based on the change number.

    Either way, when you know the ref it's easy to fetch it and check it out:

    git fetch ... refs/changes/04/2704/3 && git checkout FETCH_HEAD
    

    See a relevant thread on the repo-discuss mailing list. This information should also be found in the Gerrit documentation but I wasn't able to find it.