David Shevitz | d87d841 | 2017-08-04 08:20:27 -0700 | [diff] [blame] | 1 | = The refs/for namespace |
| 2 | |
| 3 | When pushing a new or updated commit to Gerrit, you push that commit using a |
| 4 | link:https://www.kernel.org/pub/software/scm/git/docs/gitglossary.html#def_ref[reference], |
| 5 | in the `refs/for` namespace. This reference must also define |
| 6 | the target branch, such as `refs/for/[BRANCH_NAME]`. |
| 7 | |
| 8 | For example, to create a new change on the master branch, you would use the |
| 9 | following command: |
| 10 | |
| 11 | .... |
| 12 | git push origin HEAD:refs/for/master |
| 13 | .... |
| 14 | |
| 15 | The `refs/for/[BRANCH_NAME]` syntax allows Gerrit to differentiate between |
| 16 | commits that are pushed for review and commits that are pushed directly into |
| 17 | the repository. |
| 18 | |
| 19 | Gerrit supports using either the full name or the short name for a branch. For |
| 20 | instance, this command: |
| 21 | |
| 22 | .... |
| 23 | git commit |
| 24 | git push origin HEAD:refs/for/master |
| 25 | .... |
| 26 | |
| 27 | is the same as: |
| 28 | |
| 29 | .... |
| 30 | git commit |
| 31 | git push origin HEAD:refs/for/refs/heads/master |
| 32 | .... |
| 33 | |
| 34 | Gerrit uses the `refs/for/` prefix to map the concept of "Pushing for Review" to |
| 35 | the git protocol. For the git client, it looks like every push goes to the same |
| 36 | branch, such as `refs/for/master`. In fact, for each commit pushed to this ref, |
| 37 | Gerrit creates a new ref under a `refs/changes/` namespace, which Gerrit uses |
| 38 | to track these commits. These references use the following format: |
| 39 | |
| 40 | .... |
| 41 | refs/changes/[CD]/[ABCD]/[EF] |
| 42 | .... |
| 43 | |
| 44 | Where: |
| 45 | |
| 46 | * [CD] is the last two digits of the change number |
| 47 | * [ABCD] is the change number |
| 48 | * [EF] is the patch set number |
| 49 | |
| 50 | For example: |
| 51 | |
| 52 | .... |
| 53 | refs/changes/20/884120/1 |
| 54 | .... |
| 55 | |
| 56 | You can use the change reference to fetch its corresponding commit: |
| 57 | |
| 58 | .... |
| 59 | git fetch https://[GERRIT_SERVER_URL]/[PROJECT] refs/changes/[XX]/[YYYY]/[ZZ] \ |
| 60 | && git checkout FETCH_HEAD |
| 61 | .... |
| 62 | |
| 63 | NOTE: The fetch command can be copied from the |
| 64 | link:user-review-ui.html#download[download command] in the Change screen. |
| 65 | |
| 66 | |
| 67 | GERRIT |
| 68 | ------ |
| 69 | Part of link:index.html[Gerrit Code Review] |
| 70 | |
| 71 | SEARCHBOX |
| 72 | --------- |