Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1 | = Gerrit Code Review - Change-Ids |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 2 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 3 | == Description |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 4 | |
Olivier Croquette | db675f0 | 2013-12-19 10:10:08 +0100 | [diff] [blame] | 5 | Gerrit needs to identify commits that belong to the same review. For |
| 6 | instance, when a change needs to be modified, a second commit can be uploaded |
| 7 | to address the reported issues. Gerrit allows attaching those 2 commits |
| 8 | to the same change, and relies upon a Change-Id line at the bottom of a |
| 9 | commit message to do so. With this Change-Id, Gerrit can automatically |
| 10 | associate a new version of a change back to its original review, even |
| 11 | across cherry-picks and rebases. |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 12 | |
David Pursehouse | 871670b | 2013-04-16 18:14:29 +0900 | [diff] [blame] | 13 | To be picked up by Gerrit, a Change-Id line must be in the footer |
| 14 | (last paragraph) of a commit message, and may be mixed |
| 15 | together with link:user-signedoffby.html[Signed-off-by], Acked-by, |
| 16 | or other such lines. For example: |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 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` |
Olivier Croquette | db675f0 | 2013-12-19 10:10:08 +0100 | [diff] [blame] | 36 | is the identity assigned to this change. It is independent of the |
| 37 | commit id. To avoid confusion with commit ids, Change-Ids are typically |
| 38 | prefixed with an uppercase `I`. |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 39 | |
Olivier Croquette | db675f0 | 2013-12-19 10:10:08 +0100 | [diff] [blame] | 40 | Note that a Change-Id is not necessarily unique within a Gerrit instance. It can |
| 41 | be reused among different repositories or branches (see below, |
| 42 | link:user-changeid.html[change-upload]). |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 43 | |
Edwin Kempin | 60ab853 | 2013-03-27 14:33:46 +0100 | [diff] [blame] | 44 | [[creation]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 45 | == Creation |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 46 | |
Olivier Croquette | db675f0 | 2013-12-19 10:10:08 +0100 | [diff] [blame] | 47 | Change-Ids are created at commit time on the client side. |
| 48 | A standard 'commit-msg' hook is provided by Gerrit, and |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 49 | can be installed in the local Git repository to automatically |
Olivier Croquette | db675f0 | 2013-12-19 10:10:08 +0100 | [diff] [blame] | 50 | generate and insert a Change-Id line during `git commit`, when |
| 51 | none is defined yet. |
| 52 | |
Edwin Kempin | b764e7b | 2012-07-09 11:38:47 +0200 | [diff] [blame] | 53 | To install the hook, copy it from Gerrit's daemon by executing |
| 54 | one of the following commands while being in the root directory |
| 55 | of the local Git repository: |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 56 | |
Dave Borowitz | 572d599 | 2013-05-10 16:17:10 +0100 | [diff] [blame] | 57 | $ curl -Lo .git/hooks/commit-msg http://review.example.com/tools/hooks/commit-msg |
Shawn O. Pearce | 3e4e804 | 2010-01-29 12:48:21 -0800 | [diff] [blame] | 58 | |
David Pursehouse | a37b50e | 2014-10-06 18:15:10 +0900 | [diff] [blame] | 59 | or: |
| 60 | |
Olivier Croquette | db675f0 | 2013-12-19 10:10:08 +0100 | [diff] [blame] | 61 | $ scp -p -P 29418 john.doe@review.example.com:hooks/commit-msg .git/hooks/ |
| 62 | |
Aleksander Adamowski | c8b350c | 2012-10-02 21:21:51 +0200 | [diff] [blame] | 63 | Then ensure that the execute bit is set on the hook script: |
| 64 | |
| 65 | $ chmod u+x .git/hooks/commit-msg |
| 66 | |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 67 | For more details, see link:cmd-hook-commit-msg.html[commit-msg]. |
| 68 | |
Olivier Croquette | db675f0 | 2013-12-19 10:10:08 +0100 | [diff] [blame] | 69 | [[change-upload]] |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 70 | Change Upload |
| 71 | -------------- |
| 72 | |
Olivier Croquette | db675f0 | 2013-12-19 10:10:08 +0100 | [diff] [blame] | 73 | During upload by pushing to `refs/for/*`, `refs/drafts/*` or |
| 74 | `refs/heads/*`, Gerrit will try to find an existing review the |
| 75 | uploaded commit relates to. For an existing review to match, the |
| 76 | following properties have to match: |
| 77 | |
| 78 | * Change-Id |
| 79 | * Repository name |
| 80 | * Branch name |
| 81 | |
| 82 | The following applies in the different scenarios: |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 83 | |
| 84 | * Create a new change |
| 85 | + |
Olivier Croquette | db675f0 | 2013-12-19 10:10:08 +0100 | [diff] [blame] | 86 | If no matching review is found, Gerrit will create a new change for review. |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 87 | |
| 88 | * Update an existing change |
| 89 | + |
Olivier Croquette | db675f0 | 2013-12-19 10:10:08 +0100 | [diff] [blame] | 90 | If a matching review is found, Gerrit will add the new commit as a new patch |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 91 | set on the existing change. |
| 92 | |
| 93 | * Close an existing change |
| 94 | + |
Olivier Croquette | db675f0 | 2013-12-19 10:10:08 +0100 | [diff] [blame] | 95 | If a matching review is found, and the commit is being |
| 96 | pushed directly to refs/heads/*, the existing change is updated with |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 97 | the new commit, and the change is closed and marked as merged. |
| 98 | |
| 99 | If a Change-Id line is not present in the commit message, Gerrit will |
| 100 | automatically generate its own Change-Id and display it on the web. |
| 101 | This line can be manually copied and inserted into an updated commit |
| 102 | message if additional revisions to a change are required. |
| 103 | |
Olivier Croquette | db675f0 | 2013-12-19 10:10:08 +0100 | [diff] [blame] | 104 | By default, Gerrit will prevent pushing for review if no Change-Id is provided, |
| 105 | with the following message: |
| 106 | |
| 107 | ! [remote rejected] HEAD -> refs/publish/master (missing Change-Id in commit |
| 108 | message footer) |
| 109 | |
| 110 | However, repositories can be configured to allow commits without Change-Ids |
| 111 | in the commit message by setting "Require Change-Id in commit message" to "FALSE". |
| 112 | |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 113 | For more details on using git push to upload changes to Gerrit, |
| 114 | see link:user-upload.html#push_create[creating changes by git push]. |
| 115 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 116 | == Git Tasks |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 117 | |
| 118 | [[new]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 119 | === Creating a new commit |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 120 | |
| 121 | When creating a new commit, ensure the 'commit-msg' hook has been |
| 122 | installed in your repository (see above), and don't put a Change-Id |
| 123 | line in the commit message. When you exit the editor, git will call |
| 124 | the hook, which will automatically generate and insert a unique |
| 125 | Change-Id line. You can inspect the modified message after the |
| 126 | commit is complete by executing `git show`. |
| 127 | |
| 128 | [[amend]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 129 | === Amending a commit |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 130 | |
Edwin Kempin | cdb0e00 | 2011-09-08 14:23:30 +0200 | [diff] [blame] | 131 | When amending a commit with `git commit --amend`, leave the |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 132 | Change-Id line unmodified in the commit message. This will allow |
| 133 | Gerrit to automatically update the change with the amended commit. |
| 134 | |
| 135 | [[rebase]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 136 | === Rebasing a commit |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 137 | |
| 138 | When rebasing a commit, leave the Change-Id line unmodified in the |
| 139 | commit message. This will allow Gerrit to automatically update |
| 140 | the change with the rebased commit. |
| 141 | |
| 142 | [[squash]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 143 | === Squashing commits |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 144 | |
| 145 | When squashing several commits together, try to preserve only one |
| 146 | Change-Id line, and remove the others from the commit message. |
| 147 | When faced with multiple lines, try to preserve a line which was |
| 148 | already uploaded to Gerrit Code Review, and thus has a corresponding |
| 149 | change that reviewers have already examined and left comments on. |
| 150 | If you aren't sure which lines Gerrit knows about, try copying and |
David Pursehouse | 221d4f6 | 2012-06-08 17:38:08 +0900 | [diff] [blame] | 151 | pasting the lines into the search box at the top-right of the web interface. |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 152 | |
| 153 | If Gerrit already knows about more than one Change-Id, pick one |
| 154 | to keep in the squashed commit message, and manually abandon the |
| 155 | other changes through the web interface. |
| 156 | |
| 157 | [[cherry-pick]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 158 | === Cherry-picking a commit |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 159 | |
| 160 | When cherry-picking a commit, leave the Change-Id line alone to |
| 161 | have Gerrit treat the cherry-picked commit as a replacement for |
| 162 | the existing change. This can be very useful if the project has |
| 163 | a fast-forward-only merge policy, and the submitter is downloading |
| 164 | and cherry-picking individual changes prior to submission, such as |
| 165 | by link:cmd-cherry-pick.html[gerrit-cherry-pick]. |
| 166 | |
| 167 | Or, you may wish to delete the Change-Id line and force a new |
| 168 | Change-Id to be generated automatically, thus creating an entirely |
| 169 | new change record for review. This may be useful when backporting |
| 170 | a change from the current development branch to a maintenance |
| 171 | release branch. |
| 172 | |
| 173 | [[update-old]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 174 | === Updating an old commit |
Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 175 | |
| 176 | If a commit was created before the availability of Change-Id support, |
| 177 | or was created in a Git repository that was missing the 'commit-msg' |
| 178 | hook, simply copy the "`Change-Id: I...`" line from the first line |
| 179 | of the Description section of the change and amend it to the bottom |
| 180 | of the commit message. Any subsequent uploads of the commit will |
| 181 | be automatically associated with the prior change. |
| 182 | |
| 183 | GERRIT |
| 184 | ------ |
| 185 | Part of link:index.html[Gerrit Code Review] |
Yuxuan 'fishy' Wang | 99cb68d | 2013-10-31 17:26:00 -0700 | [diff] [blame] | 186 | |
| 187 | SEARCHBOX |
| 188 | --------- |