Shawn O. Pearce | e31d02c | 2009-12-08 12:21:37 -0800 | [diff] [blame] | 1 | Gerrit Code Review - Change-Ids |
| 2 | =============================== |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 3 | |
| 4 | Description |
| 5 | ----------- |
| 6 | |
| 7 | Gerrit Code Review sometimes relies upon Change-Id lines in the |
| 8 | bottom of a commit message to uniquely identify a change across all |
| 9 | drafts of it. By including a unique Change-Id in the commit message, |
| 10 | Gerrit can automatically associate a new version of a change back |
| 11 | to its original review, even across cherry-picks and rebases. |
| 12 | |
| 13 | To be picked up by Gerrit, a Change-Id line must be in the bottom |
| 14 | portion (last paragraph) of a commit message, and may be mixed |
| 15 | together with the Signed-off-by, Acked-by, or other such footers. |
| 16 | For example: |
| 17 | |
| 18 | ---- |
| 19 | $ git log -1 |
| 20 | commit 29a6bb1a059aef021ac39d342499191278518d1d |
| 21 | Author: A. U. Thor <author@example.com> |
| 22 | Date: Thu Aug 20 12:46:50 2009 -0700 |
| 23 | |
| 24 | Improve foo widget by attaching a bar. |
| 25 | |
| 26 | We want a bar, because it improves the foo by providing more |
| 27 | wizbangery to the dowhatimeanery. |
| 28 | |
| 29 | Bug: #42 |
| 30 | Change-Id: Ic8aaa0728a43936cd4c6e1ed590e01ba8f0fbf5b |
| 31 | Signed-off-by: A. U. Thor <author@example.com> |
| 32 | CC: R. E. Viewer <reviewer@example.com> |
| 33 | ---- |
| 34 | |
| 35 | In the above example, `Ic8aaa0728a43936cd4c6e1ed590e01ba8f0fbf5b` |
| 36 | is the unique identity assigned to this change. It does not match |
| 37 | the commit name, `29a6...`, as the change may have been amended or |
| 38 | rebased to address reviewer comments since its initial inception. |
| 39 | |
| 40 | To avoid confusion with commit names, Change-Ids typically are with |
| 41 | an uppercase `I`. |
| 42 | |
| 43 | Creation |
| 44 | -------- |
| 45 | |
| 46 | Gerrit Code Review provides a standard 'commit-msg' hook which |
| 47 | can be installed in the local Git repository to automatically |
| 48 | create and insert a unique Change-Id line during `git commit`. |
Shawn O. Pearce | 3e4e804 | 2010-01-29 12:48:21 -0800 | [diff] [blame] | 49 | To install the hook, copy it from Gerrit's daemon: |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 50 | |
Edwin Kempin | f178f27 | 2011-02-28 08:43:56 +0100 | [diff] [blame] | 51 | $ scp -p -P 29418 john.doe@review.example.com:hooks/commit-msg .git/hooks/ |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 52 | |
Shawn O. Pearce | 3e4e804 | 2010-01-29 12:48:21 -0800 | [diff] [blame] | 53 | $ curl http://review.example.com/tools/hooks/commit-msg |
| 54 | |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 55 | For more details, see link:cmd-hook-commit-msg.html[commit-msg]. |
| 56 | |
| 57 | Change Upload |
| 58 | -------------- |
| 59 | |
| 60 | During upload by pushing to a `refs/for/\*` or `refs/heads/\*` |
| 61 | branch, Gerrit will use the Change-Id line to: |
| 62 | |
| 63 | * Create a new change |
| 64 | + |
| 65 | If this is the first time it has seen the Change-Id mentioned in |
| 66 | the commit message, Gerrit will create a new change for review. |
| 67 | |
| 68 | * Update an existing change |
| 69 | + |
| 70 | If Gerrit has seen this Change-Id before, but has not yet seen this |
| 71 | new commit object, Gerrit will add the new commit as a new patch |
| 72 | set on the existing change. |
| 73 | |
| 74 | * Close an existing change |
| 75 | + |
| 76 | If Gerrit has seen this Change-Id before, and the commit is being |
| 77 | pushed directly into a branch, the existing change is updated with |
| 78 | the new commit, and the change is closed and marked as merged. |
| 79 | |
| 80 | If a Change-Id line is not present in the commit message, Gerrit will |
| 81 | automatically generate its own Change-Id and display it on the web. |
| 82 | This line can be manually copied and inserted into an updated commit |
| 83 | message if additional revisions to a change are required. |
| 84 | |
| 85 | For more details on using git push to upload changes to Gerrit, |
| 86 | see link:user-upload.html#push_create[creating changes by git push]. |
| 87 | |
| 88 | Git Tasks |
| 89 | --------- |
| 90 | |
| 91 | [[new]] |
| 92 | Creating a new commit |
| 93 | ~~~~~~~~~~~~~~~~~~~~~ |
| 94 | |
| 95 | When creating a new commit, ensure the 'commit-msg' hook has been |
| 96 | installed in your repository (see above), and don't put a Change-Id |
| 97 | line in the commit message. When you exit the editor, git will call |
| 98 | the hook, which will automatically generate and insert a unique |
| 99 | Change-Id line. You can inspect the modified message after the |
| 100 | commit is complete by executing `git show`. |
| 101 | |
| 102 | [[amend]] |
| 103 | Amending a commit |
| 104 | ~~~~~~~~~~~~~~~~~ |
| 105 | |
| 106 | When amending a commit with `git commit \--amend`, leave the |
| 107 | Change-Id line unmodified in the commit message. This will allow |
| 108 | Gerrit to automatically update the change with the amended commit. |
| 109 | |
| 110 | [[rebase]] |
| 111 | Rebasing a commit |
| 112 | ~~~~~~~~~~~~~~~~~ |
| 113 | |
| 114 | When rebasing a commit, leave the Change-Id line unmodified in the |
| 115 | commit message. This will allow Gerrit to automatically update |
| 116 | the change with the rebased commit. |
| 117 | |
| 118 | [[squash]] |
| 119 | Squashing commits |
| 120 | ~~~~~~~~~~~~~~~~~ |
| 121 | |
| 122 | When squashing several commits together, try to preserve only one |
| 123 | Change-Id line, and remove the others from the commit message. |
| 124 | When faced with multiple lines, try to preserve a line which was |
| 125 | already uploaded to Gerrit Code Review, and thus has a corresponding |
| 126 | change that reviewers have already examined and left comments on. |
| 127 | If you aren't sure which lines Gerrit knows about, try copying and |
| 128 | pasting the lines into the search box in the top-right. |
| 129 | |
| 130 | If Gerrit already knows about more than one Change-Id, pick one |
| 131 | to keep in the squashed commit message, and manually abandon the |
| 132 | other changes through the web interface. |
| 133 | |
| 134 | [[cherry-pick]] |
| 135 | Cherry-picking a commit |
| 136 | ~~~~~~~~~~~~~~~~~~~~~~~ |
| 137 | |
| 138 | When cherry-picking a commit, leave the Change-Id line alone to |
| 139 | have Gerrit treat the cherry-picked commit as a replacement for |
| 140 | the existing change. This can be very useful if the project has |
| 141 | a fast-forward-only merge policy, and the submitter is downloading |
| 142 | and cherry-picking individual changes prior to submission, such as |
| 143 | by link:cmd-cherry-pick.html[gerrit-cherry-pick]. |
| 144 | |
| 145 | Or, you may wish to delete the Change-Id line and force a new |
| 146 | Change-Id to be generated automatically, thus creating an entirely |
| 147 | new change record for review. This may be useful when backporting |
| 148 | a change from the current development branch to a maintenance |
| 149 | release branch. |
| 150 | |
| 151 | [[update-old]] |
| 152 | Updating an old commit |
| 153 | ~~~~~~~~~~~~~~~~~~~~~~ |
| 154 | |
| 155 | If a commit was created before the availability of Change-Id support, |
| 156 | or was created in a Git repository that was missing the 'commit-msg' |
| 157 | hook, simply copy the "`Change-Id: I...`" line from the first line |
| 158 | of the Description section of the change and amend it to the bottom |
| 159 | of the commit message. Any subsequent uploads of the commit will |
| 160 | be automatically associated with the prior change. |
| 161 | |
| 162 | GERRIT |
| 163 | ------ |
| 164 | Part of link:index.html[Gerrit Code Review] |