5

I am following an example from our IT department, and I would like to understand what this command is doing exactly:

git fetch origin +refs/changes/*:refs/remotes/origin/changes/*

To give some frame of reference, this is part of a continuous integration (CI) tool, and this is part of the step to checkout the code to test. The CI build is triggered by pushing to Gerrit with:

git push origin HEAD:refs/for/master

I secondary question, is if I wanted to push the change into a development branch could I use:

git push origin HEAD:refs/for/development
4

2 回答 2

2

I don't know anything about gerrit. But I can say something about the first git command you mention.

The last parts of the commands you mention are called the refspecs. You can read about what they do in the Refspec chapter of the Pro Git book. In short:

git fetch origin +refs/changes/*:refs/remotes/origin/changes/*

This says that, for the origin remote, fetch the commits of the branches that, in the origin repository, are in the refs/changes directory in the git directory (i.e. .git/refs/changes/ in a standard repository and refs/changes in a normal bare repository). It will copy those branches to the local directory .git/refs/remotes/origin/changes/. Lastly, as per normal fetch behavior, it will copy the commits belonging to those branches to the .git/object directory.

The standard refspec is +refs/heads/*:refs/remotes/origin/* so the refs/changes looks a bit strange to me. That is not a standard Git directory, but perhaps it is a Gerrit thing. The structure refs/remotes/origin/changes looks like changes is a branch in your local repository.

于 2013-06-30T07:02:10.653 回答
1

A typical pull of a patch would look like this: git pull ssh://www.example/com:29418/project refs/changes/24/24/2

This would pull your project plus the second patch set of change 24. So when you pull all the changes that can be a lot.

I would recommend that you use Jenkins (CI) plus the Gerrit plugin and that make sure you specify the choosing strategy as Gerrit Trigger. This will then make sure that you build will test the appropriate change set.

Yes, you can push to a development branch. Of course you need to make sure you have the correct rights. Best is to create the branch in Gerrit first, this way you do not have to give the "create reference" right and prevent creating branches by mistake by spelling mistake for example.

于 2013-07-01T00:48:38.977 回答