简体   繁体   中英

How do I pull/cherry-pick a gerrit commit/patch to a branch using a http link to the commit?

I'm trying to pull a particular gerrit commit/patch to a branch. I'm not too familiar with gerrit but it seems like for usual case there are things called "patch" which are like a group of commits lumped together. In most cases I see some steps something along the lines of

Clone       $git clone ssh:me@gerrit.server.com/potato
Checkout    $git checkout fried_branch
Fetch       $git fetch ssh:me@gerrit.server.com/potato refs/changes/01/23456/7
Cherry-pick $git cherry-pick FETCH_HEAD
Pull        $git pull ssh:me@gerrit.server.com/potato refs/change/01/23456/7

where the refs/changes is used to find the commit/patches. Instead I am given a http link to gerrit commit/patch along the line of

http://gerrit.server.com:8080/#/c/12345/

I assume I need to change the Fetch and pull step of the clone, checkout, fetch, cherry-pick, pull but I'm not sure how to do this this with the http link instead of refs. How do I change the step to work with http?

A Gerrit change is a single commit, but there can be more than one version of the commit in the same change; each version is called a patch set .

You don't fetch a change from Gerrit; you actually fetch a particular patch set for a change. The URL you need to use will include not just the change number, but the patch set number too.

The link you've been given:

http://gerrit.server.com:8080/#/c/12345/

tells you the change number (12345), but doesn't tell you which patch set number to use. In fact it doesn't even tell you which repository the change is for (a Gerrit server can host many repositories).

If you go to the URL in your browser, you should be taken to the latest patch set for the change. You should see Download ⯆ in the top right corner. Look for the "Cherry Pick" line, which gives you two commands: a git fetch command to fetch the patch set (ie commit), and a git cherry-pick command to cherry-pick the fetched commit to whatever branch you're currently on.

Here's an example from the Eclipse Gerrit. This change:

https://git.eclipse.org/r/#/c/154809/

is for the jdt/eclipse.jdt.debug repository, and has 3 patch sets at the time of writing. This is a link to patch set 3:

https://git.eclipse.org/r/#/c/154809/3

In the top right, the cherry pick commands are:

git fetch https://git.eclipse.org/r/jdt/eclipse.jdt.debug refs/changes/09/154809/3 && git cherry-pick FETCH_HEAD

In the git fetch command, 09 are the last two digits of the change number, 154809 is the full change number, and 3 is the patch set number.

I find a walk around for this, but need to use git-review. first you just need to get the last part of the url http://gerrit.server.com:8080/#/c/12345/ .

git review -d 12345
git checkout master # switch to your work branch
git cherry-pick FETCH_HEAD

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM