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