blob: b0e365f95fc06bfe2cc833feb6a4c2d472501335 [file] [log] [blame]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08001= Gerrit Code Review - Change-Ids
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -07002
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08003== Description
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -07004
Olivier Croquettedb675f02013-12-19 10:10:08 +01005Gerrit needs to identify commits that belong to the same review. For
6instance, when a change needs to be modified, a second commit can be uploaded
7to address the reported issues. Gerrit allows attaching those 2 commits
8to the same change, and relies upon a Change-Id line at the bottom of a
9commit message to do so. With this Change-Id, Gerrit can automatically
10associate a new version of a change back to its original review, even
11across cherry-picks and rebases.
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070012
David Pursehouse871670b2013-04-16 18:14:29 +090013To 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
15together with link:user-signedoffby.html[Signed-off-by], Acked-by,
16or other such lines. For example:
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070017
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
35In the above example, `Ic8aaa0728a43936cd4c6e1ed590e01ba8f0fbf5b`
Olivier Croquettedb675f02013-12-19 10:10:08 +010036is the identity assigned to this change. It is independent of the
37commit id. To avoid confusion with commit ids, Change-Ids are typically
38prefixed with an uppercase `I`.
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070039
Olivier Croquettedb675f02013-12-19 10:10:08 +010040Note that a Change-Id is not necessarily unique within a Gerrit instance. It can
41be reused among different repositories or branches (see below,
42link:user-changeid.html[change-upload]).
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070043
Edwin Kempin60ab8532013-03-27 14:33:46 +010044[[creation]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080045== Creation
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070046
Olivier Croquettedb675f02013-12-19 10:10:08 +010047Change-Ids are created at commit time on the client side.
48A standard 'commit-msg' hook is provided by Gerrit, and
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070049can be installed in the local Git repository to automatically
Olivier Croquettedb675f02013-12-19 10:10:08 +010050generate and insert a Change-Id line during `git commit`, when
51none is defined yet.
52
Edwin Kempinb764e7b2012-07-09 11:38:47 +020053To install the hook, copy it from Gerrit's daemon by executing
54one of the following commands while being in the root directory
55of the local Git repository:
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070056
Dave Borowitz572d5992013-05-10 16:17:10 +010057 $ curl -Lo .git/hooks/commit-msg http://review.example.com/tools/hooks/commit-msg
Shawn O. Pearce3e4e8042010-01-29 12:48:21 -080058
David Pursehousea37b50e2014-10-06 18:15:10 +090059or:
60
Olivier Croquettedb675f02013-12-19 10:10:08 +010061 $ scp -p -P 29418 john.doe@review.example.com:hooks/commit-msg .git/hooks/
62
Aleksander Adamowskic8b350c2012-10-02 21:21:51 +020063Then ensure that the execute bit is set on the hook script:
64
65 $ chmod u+x .git/hooks/commit-msg
66
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070067For more details, see link:cmd-hook-commit-msg.html[commit-msg].
68
Olivier Croquettedb675f02013-12-19 10:10:08 +010069[[change-upload]]
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070070Change Upload
71--------------
72
Olivier Croquettedb675f02013-12-19 10:10:08 +010073During upload by pushing to `refs/for/*`, `refs/drafts/*` or
74`refs/heads/*`, Gerrit will try to find an existing review the
75uploaded commit relates to. For an existing review to match, the
76following properties have to match:
77
78* Change-Id
79* Repository name
80* Branch name
81
82The following applies in the different scenarios:
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070083
84* Create a new change
85+
Olivier Croquettedb675f02013-12-19 10:10:08 +010086If no matching review is found, Gerrit will create a new change for review.
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070087
88* Update an existing change
89+
Olivier Croquettedb675f02013-12-19 10:10:08 +010090If a matching review is found, Gerrit will add the new commit as a new patch
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070091set on the existing change.
92
93* Close an existing change
94+
Olivier Croquettedb675f02013-12-19 10:10:08 +010095If a matching review is found, and the commit is being
96pushed directly to refs/heads/*, the existing change is updated with
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070097the new commit, and the change is closed and marked as merged.
98
99If a Change-Id line is not present in the commit message, Gerrit will
100automatically generate its own Change-Id and display it on the web.
101This line can be manually copied and inserted into an updated commit
102message if additional revisions to a change are required.
103
Olivier Croquettedb675f02013-12-19 10:10:08 +0100104By default, Gerrit will prevent pushing for review if no Change-Id is provided,
105with the following message:
106
107 ! [remote rejected] HEAD -> refs/publish/master (missing Change-Id in commit
108 message footer)
109
110However, repositories can be configured to allow commits without Change-Ids
111in the commit message by setting "Require Change-Id in commit message" to "FALSE".
112
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700113For more details on using git push to upload changes to Gerrit,
114see link:user-upload.html#push_create[creating changes by git push].
115
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800116== Git Tasks
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700117
118[[new]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800119=== Creating a new commit
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700120
121When creating a new commit, ensure the 'commit-msg' hook has been
122installed in your repository (see above), and don't put a Change-Id
123line in the commit message. When you exit the editor, git will call
124the hook, which will automatically generate and insert a unique
125Change-Id line. You can inspect the modified message after the
126commit is complete by executing `git show`.
127
128[[amend]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800129=== Amending a commit
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700130
Edwin Kempincdb0e002011-09-08 14:23:30 +0200131When amending a commit with `git commit --amend`, leave the
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700132Change-Id line unmodified in the commit message. This will allow
133Gerrit to automatically update the change with the amended commit.
134
135[[rebase]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800136=== Rebasing a commit
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700137
138When rebasing a commit, leave the Change-Id line unmodified in the
139commit message. This will allow Gerrit to automatically update
140the change with the rebased commit.
141
142[[squash]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800143=== Squashing commits
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700144
145When squashing several commits together, try to preserve only one
146Change-Id line, and remove the others from the commit message.
147When faced with multiple lines, try to preserve a line which was
148already uploaded to Gerrit Code Review, and thus has a corresponding
149change that reviewers have already examined and left comments on.
150If you aren't sure which lines Gerrit knows about, try copying and
David Pursehouse221d4f62012-06-08 17:38:08 +0900151pasting the lines into the search box at the top-right of the web interface.
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700152
153If Gerrit already knows about more than one Change-Id, pick one
154to keep in the squashed commit message, and manually abandon the
155other changes through the web interface.
156
157[[cherry-pick]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800158=== Cherry-picking a commit
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700159
160When cherry-picking a commit, leave the Change-Id line alone to
161have Gerrit treat the cherry-picked commit as a replacement for
162the existing change. This can be very useful if the project has
163a fast-forward-only merge policy, and the submitter is downloading
164and cherry-picking individual changes prior to submission, such as
165by link:cmd-cherry-pick.html[gerrit-cherry-pick].
166
167Or, you may wish to delete the Change-Id line and force a new
168Change-Id to be generated automatically, thus creating an entirely
169new change record for review. This may be useful when backporting
170a change from the current development branch to a maintenance
171release branch.
172
173[[update-old]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800174=== Updating an old commit
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700175
176If a commit was created before the availability of Change-Id support,
177or was created in a Git repository that was missing the 'commit-msg'
178hook, simply copy the "`Change-Id: I...`" line from the first line
179of the Description section of the change and amend it to the bottom
180of the commit message. Any subsequent uploads of the commit will
181be automatically associated with the prior change.
182
183GERRIT
184------
185Part of link:index.html[Gerrit Code Review]
Yuxuan 'fishy' Wang99cb68d2013-10-31 17:26:00 -0700186
187SEARCHBOX
188---------