blob: aee044acae2f770701060d6a4f4dd7d3f2c2853e [file] [log] [blame]
Andrew Gerrand7cb21a72012-01-19 11:24:54 +11001<!--{
2 "Title": "Contribution Guidelines"
3}-->
Russ Coxfb39a4d2009-10-23 15:24:08 -07004
Russ Cox6c7f9f62009-11-09 16:56:17 -08005<h2 id="Introduction">Introduction</h2>
Rob Pike5b72f9c2009-11-01 20:48:21 -08006
7<p>
Russ Coxd55abfd2009-12-09 14:05:12 -08008This document explains how to contribute changes to the Go project.
Andrew Gerrand968f0df2014-12-12 13:53:29 +11009It assumes you have followed the
Jonathan Feinberg452f40f2012-09-26 14:39:31 -040010<a href="/doc/install/source">installation instructions</a> and
Russ Coxd55abfd2009-12-09 14:05:12 -080011have <a href="code.html">written and tested your code</a>.
Andrew Gerrand968f0df2014-12-12 13:53:29 +110012</p>
Andrew Gerrandd708e922014-12-10 09:29:35 +110013
14<p>
Russ Coxd55abfd2009-12-09 14:05:12 -080015(Note that the <code>gccgo</code> frontend lives elsewhere;
Ian Lance Taylor2528f332009-11-06 14:15:41 -080016see <a href="gccgo_contribute.html">Contributing to gccgo</a>.)
Russ Cox38a41ee2009-11-06 10:04:22 -080017</p>
Russ Coxfb39a4d2009-10-23 15:24:08 -070018
Rob Pike96ee38b2009-12-17 12:12:47 +110019<h2 id="Design">Discuss your design</h2>
20
21<p>
22The project welcomes submissions but please let everyone know what
23you're working on if you want it to become part of the main repository.
24</p>
25
26<p>
27Before undertaking to write something new for the Go project, send
Brad Fitzpatrick967901a2014-03-05 14:09:03 -080028mail to the <a href="https://groups.google.com/group/golang-nuts">mailing
Rob Pike96ee38b2009-12-17 12:12:47 +110029list</a> to discuss what you plan to do. This gives everyone a
30chance to validate the design, helps prevent duplication of effort,
31and ensures that the idea fits inside the goals for the language
32and tools. It also guarantees that the design is sound before code
33is written; the code review tool is not the place for high-level
34discussions.
35</p>
36
37<p>
38In short, send mail before you code.
39And don't start the discussion by mailing a change list!
40</p>
41
Russ Coxd55abfd2009-12-09 14:05:12 -080042<h2 id="Testing">Testing redux</h2>
Russ Cox830813f2009-11-08 21:08:27 -080043
44<p>
Russ Coxd55abfd2009-12-09 14:05:12 -080045You've <a href="code.html">written and tested your code</a>, but
46before sending code out for review, run all the tests for the whole
47tree to make sure the changes don't break other packages or programs:
Russ Cox38a41ee2009-11-06 10:04:22 -080048</p>
49
50<pre>
Nathan John Youngmand5f208c2014-03-17 09:35:04 +110051$ cd go/src
52$ ./all.bash
Russ Cox38a41ee2009-11-06 10:04:22 -080053</pre>
54
55<p>
Nathan John Youngmand5f208c2014-03-17 09:35:04 +110056(To build under Windows use <code>all.bat</code>.)
57</p>
58
59<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +110060After running for a while, the command should print
61"<code>ALL</code> <code>TESTS</code> <code>PASSED</code>".
Russ Cox38a41ee2009-11-06 10:04:22 -080062</p>
63
Russ Cox6c7f9f62009-11-09 16:56:17 -080064<h2 id="Code_review">Code review</h2>
Russ Cox38a41ee2009-11-06 10:04:22 -080065
66<p>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -080067Changes to Go must be reviewed before they are accepted,
Russ Cox38a41ee2009-11-06 10:04:22 -080068no matter who makes the change.
Andrew Gerrand722f7d22014-12-18 11:42:25 +110069A custom git command called <code>git-codereview</code>,
Andrew Gerrandd708e922014-12-10 09:29:35 +110070discussed below, helps manage the code review process through a Google-hosted
71<a href="https://go-review.googlesource.com/">instance</a> of the code review
72system called <a href="https://code.google.com/p/gerrit/">Gerrit</a>.
Russ Cox38a41ee2009-11-06 10:04:22 -080073</p>
74
Andrew Gerrandd708e922014-12-10 09:29:35 +110075<h3>Set up authentication for code review</h3>
Russ Cox9ad14c92009-11-06 10:33:46 -080076
Russ Cox38a41ee2009-11-06 10:04:22 -080077<p>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -080078Gerrit uses Google Accounts for authentication. If you don't have
79a Google Account, you can create an account which
80<a href="https://www.google.com/accounts/NewAccount">includes
81a new Gmail email account</a> or create an account associated
82<a href="https://accounts.google.com/SignUpWithoutGmail">with your existing
83email address</a>.
Andrew Gerrandd708e922014-12-10 09:29:35 +110084</p>
85
86<p>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -080087The email address associated with the Google Account you use will be recorded in
88the <a href="https://go.googlesource.com/go/+log/">change log</a>
89and in the <a href="/CONTRIBUTORS">contributors file</a>.
Andrew Gerrandd708e922014-12-10 09:29:35 +110090</p>
91
92<p>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -080093To set up your account in Gerrit, visit
94<a href="https://go.googlesource.com">go.googlesource.com</a>
95and click on "Generate Password" in the page's top right menu bar.
Andrew Gerrandd708e922014-12-10 09:29:35 +110096</p>
97
98<p>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -080099You will be redirected to accounts.google.com to sign in.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100100</p>
101
102<p>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800103Once signed in, you are returned back to go.googlesource.com to "Configure Git".
104Follow the instructions on the page.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100105(If you are on a Windows computer, you should instead follow the instructions
106in the yellow box to run the command.)
107</p>
108
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800109<p>
110Your secret authentication token is now in a <code>.gitcookie</code> file
111and Git is configured to use this file.
112</p>
113
Andrew Gerrandd708e922014-12-10 09:29:35 +1100114<h3>Register with Gerrit</h3>
115
116<p>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800117Now that you have your authentication token,
118you need to register your account with Gerrit.
119To do this, visit
120<a href="https://go-review.googlesource.com/login/">
121go-review.googlesource.com/login/</a>. You will immediately be redirected
122to Google Accounts. Sign in using the same Google Account you used above.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100123That is all that is required.
124</p>
125
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100126<h3>Install the git-codereview command</h3>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100127
128<p>
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100129Now install the <code>git-codereview</code> command by running,
Russ Cox38a41ee2009-11-06 10:04:22 -0800130</p>
131
132<pre>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800133$ go get -u golang.org/x/review/git-codereview
Russ Cox38a41ee2009-11-06 10:04:22 -0800134</pre>
135
Andrew Gerrandd708e922014-12-10 09:29:35 +1100136<p>
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100137Make sure <code>git-codereview</code> is installed in your shell path, so that the
Andrew Gerrandd708e922014-12-10 09:29:35 +1100138<code>git</code> command can find it. Check that
Russ Cox38a41ee2009-11-06 10:04:22 -0800139</p>
140
Andrew Gerrandd708e922014-12-10 09:29:35 +1100141<pre>
Andrew Gerrand0293b7e2014-12-18 12:55:22 +1100142$ git codereview help
Andrew Gerrandd708e922014-12-10 09:29:35 +1100143</pre>
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100144
Andrew Gerrandd708e922014-12-10 09:29:35 +1100145<p>
146prints help text, not an error.
Russ Cox38a41ee2009-11-06 10:04:22 -0800147</p>
148
Andrew Gerrandd708e922014-12-10 09:29:35 +1100149<p>
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100150Note to Git aficionados: The <code>git-codereview</code> command is not required to
Andrew Gerrandd708e922014-12-10 09:29:35 +1100151upload and manage Gerrit code reviews. For those who prefer plain Git, the text
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100152below gives the Git equivalent of each git-codereview command. If you do use plain
153Git, note that you still need the commit hooks that the git-codereview command
Andrew Gerrandd708e922014-12-10 09:29:35 +1100154configures; those hooks add a Gerrit <code>Change-Id</code> line to the commit
155message and check that all Go source files have been formatted with gofmt. Even
156if you intend to use plain Git for daily work, install the hooks in a new Git
Oling Catce365522014-12-14 14:32:56 +0800157checkout by running <code>git-codereview</code> <code>hooks</code>.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100158</p>
159
160<h3>Set up git aliases</h3>
161
162<p>
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100163The <code>git-codereview</code> command can be run directly from the shell
Andrew Gerrandd708e922014-12-10 09:29:35 +1100164by typing, for instance,
165</p>
166
167<pre>
Andrew Gerrand0293b7e2014-12-18 12:55:22 +1100168$ git codereview sync
Andrew Gerrandd708e922014-12-10 09:29:35 +1100169</pre>
170
171<p>
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100172but it is more convenient to set up aliases for <code>git-codereview</code>'s own
Andrew Gerrandd708e922014-12-10 09:29:35 +1100173subcommands, so that the above becomes,
174</p>
175
176<pre>
177$ git sync
178</pre>
179
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100180<p>
181The <code>git-codereview</code> subcommands have been chosen to be distinct from
Andrew Gerrandd708e922014-12-10 09:29:35 +1100182Git's own, so it's safe to do so.
183</p>
184
185<p>
186The aliases are optional, but in the rest of this document we will assume
187they are installed.
188To install them, copy this text into your Git configuration file
189(usually <code>.gitconfig</code> in your home directory):
190</p>
191
192<pre>
193[alias]
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100194 change = codereview change
195 gofmt = codereview gofmt
196 mail = codereview mail
197 pending = codereview pending
198 submit = codereview submit
199 sync = codereview sync
Andrew Gerrandd708e922014-12-10 09:29:35 +1100200</pre>
201
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100202<h3>Understanding the git-codereview command</h3>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100203
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100204<p>After installing the <code>git-codereview</code> command, you can run</p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100205
206<pre>
Andrew Gerrand0293b7e2014-12-18 12:55:22 +1100207$ git codereview help
Andrew Gerrandd708e922014-12-10 09:29:35 +1100208</pre>
209
210<p>
211to learn more about its commands.
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100212You can also read the <a href="https://godoc.org/golang.org/x/review/git-codereview">command documentation</a>.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100213</p>
214
215<h3>Switch to the master branch</h3>
Andrew Gerrand32387052012-06-05 00:55:45 +1000216
217<p>
218Most Go installations use a release branch, but new changes should
Andrew Gerrandd708e922014-12-10 09:29:35 +1100219only be made based on the master branch.
220(They may be applied later to a release branch as part of the release process,
221but most contributors won't do this themselves.)
222Before making a change, make sure you start on the master branch:
Andrew Gerrand32387052012-06-05 00:55:45 +1000223</p>
224
225<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100226$ git checkout master
227$ git sync
Andrew Gerrand32387052012-06-05 00:55:45 +1000228</pre>
229
Andrew Gerrandd708e922014-12-10 09:29:35 +1100230<p>
231(In Git terms, <code>git</code> <code>sync</code> runs
232<code>git</code> <code>pull</code> <code>-r</code>.)
233</p>
234
Russ Cox9ad14c92009-11-06 10:33:46 -0800235<h3>Make a change</h3>
Russ Cox38a41ee2009-11-06 10:04:22 -0800236
237<p>
238The entire checked-out tree is writable.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100239Once you have edited files, you must tell Git that they have been modified.
240You must also tell Git about any files that are added, removed, or renamed files.
241These operations are done with the usual Git commands,
242<code>git</code> <code>add</code>,
243<code>git</code> <code>rm</code>,
244and
245<code>git</code> <code>mv</code>.
Russ Cox38a41ee2009-11-06 10:04:22 -0800246</p>
247
Andrew Gerrandd708e922014-12-10 09:29:35 +1100248<p>
249If you wish to checkpoint your work, or are ready to send the code out for review, run</p>
Russ Cox38a41ee2009-11-06 10:04:22 -0800250
251<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100252$ git change <i>&lt;branch&gt;</i>
Russ Cox38a41ee2009-11-06 10:04:22 -0800253</pre>
254
Andrew Gerrandd708e922014-12-10 09:29:35 +1100255<p>
256from any directory in your Go repository to commit the changes so far.
257The name <i>&lt;branch&gt;</i> is an arbitrary one you choose to identify the
258local branch containing your changes.
259</p>
260
261<p>
262(In Git terms, <code>git</code> <code>change</code> <code>&lt;branch&gt;</code>
263runs <code>git</code> <code>checkout</code> <code>-b</code> <code>branch</code>,
264then <code>git</code> <code>branch</code> <code>--set-upstream-to</code> <code>origin/master</code>,
265then <code>git</code> <code>commit</code>.)
266</p>
267
268<p>
269Git will open a change description file in your editor.
270(It uses the editor named by the <code>$EDITOR</code> environment variable,
271<code>vi</code> by default.)
Russ Cox38a41ee2009-11-06 10:04:22 -0800272The file will look like:
273</p>
274
275<pre>
Russ Cox38a41ee2009-11-06 10:04:22 -0800276
Andrew Gerrandd708e922014-12-10 09:29:35 +1100277# Please enter the commit message for your changes. Lines starting
278# with '#' will be ignored, and an empty message aborts the commit.
279# On branch foo
280# Changes not staged for commit:
281# modified: editedfile.go
282#
Russ Cox38a41ee2009-11-06 10:04:22 -0800283</pre>
284
285<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100286At the beginning of this file is a blank line; replace it
287with a thorough description of your change.
Nigel Tao3f383422011-01-05 13:00:08 +1100288The first line of the change description is conventionally a one-line
289summary of the change, prefixed by the primary affected package,
Andrew Gerrandd708e922014-12-10 09:29:35 +1100290and is used as the subject for code review mail.
291The rest of the
292description elaborates and should provide context for the
293change and explain what it does.
294If there is a helpful reference, mention it here.
Russ Cox696e8022009-11-07 18:56:00 -0800295</p>
296
297<p>
298After editing, the template might now read:
Russ Cox38a41ee2009-11-06 10:04:22 -0800299</p>
300
301<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100302math: improved Sin, Cos and Tan precision for very large arguments
Russ Cox38a41ee2009-11-06 10:04:22 -0800303
Andrew Gerrandd708e922014-12-10 09:29:35 +1100304The existing implementation has poor numerical properties for
305large arguments, so use the McGillicutty algorithm to improve
306accuracy above 1e10.
Russ Cox38a41ee2009-11-06 10:04:22 -0800307
Andrew Gerrandd708e922014-12-10 09:29:35 +1100308The algorithm is described at http://wikipedia.org/wiki/McGillicutty_Algorithm
Russ Cox696e8022009-11-07 18:56:00 -0800309
Andrew Gerrandd708e922014-12-10 09:29:35 +1100310Fixes #159
Russ Cox38a41ee2009-11-06 10:04:22 -0800311
Andrew Gerrandd708e922014-12-10 09:29:35 +1100312# Please enter the commit message for your changes. Lines starting
313# with '#' will be ignored, and an empty message aborts the commit.
314# On branch foo
315# Changes not staged for commit:
316# modified: editedfile.go
317#
Russ Cox38a41ee2009-11-06 10:04:22 -0800318</pre>
319
320<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100321The commented section of the file lists all the modified files in your client.
322It is best to keep unrelated changes in different change lists,
323so if you see a file listed that should not be included, abort
324the command and move that file to a different branch.
Russ Cox38a41ee2009-11-06 10:04:22 -0800325</p>
326
327<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100328The special notation "Fixes #159" associates the change with issue 159 in the
329<a href="https://golang.org/issue/159">Go issue tracker</a>.
330When this change is eventually submitted, the issue
331tracker will automatically mark the issue as fixed.
332(There are several such conventions, described in detail in the
333<a href="https://help.github.com/articles/closing-issues-via-commit-messages/">GitHub Issue Tracker documentation</a>.)
334</p>
Russ Cox38a41ee2009-11-06 10:04:22 -0800335
336<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100337Once you have finished writing the commit message,
338save the file and exit the editor.
339</p>
340
341<p>
342If you wish to do more editing, re-stage your changes using
343<code>git</code> <code>add</code>, and then run
Russ Cox38a41ee2009-11-06 10:04:22 -0800344</p>
345
346<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100347$ git change
Russ Cox38a41ee2009-11-06 10:04:22 -0800348</pre>
349
Andrew Gerrandd708e922014-12-10 09:29:35 +1100350<p>
351to update the change description and incorporate the staged changes. The
352change description contains a <code>Change-Id</code> line near the bottom,
353added by a Git commit hook during the initial
354<code>git</code> <code>change</code>.
355That line is used by Gerrit to match successive uploads of the same change.
356Do not edit or delete it.
357</p>
358
359<p>
360(In Git terms, <code>git</code> <code>change</code> with no branch name
361runs <code>git</code> <code>commit</code> <code>--amend</code>.)
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100362</p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100363
Bill Thiede822b2cb2014-07-03 17:42:23 -0400364<h3>Mail the change for review</h3>
365
366<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100367Once the change is ready, mail it out for review:
Bill Thiede822b2cb2014-07-03 17:42:23 -0400368</p>
369
370<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100371$ git mail
Bill Thiede822b2cb2014-07-03 17:42:23 -0400372</pre>
373
Andrew Gerrandd708e922014-12-10 09:29:35 +1100374<p>
375You can specify a reviewer or CC interested parties
376using the <code>-r</code> or <code>-cc</code> options.
377Both accept a comma-separated list of email addresses:
378</p>
Bill Thiede822b2cb2014-07-03 17:42:23 -0400379
Andrew Gerrandd708e922014-12-10 09:29:35 +1100380<pre>
381$ git mail -r joe@golang.org -cc mabel@example.com,math-nuts@swtch.com
382</pre>
383
384<p>
385Unless explicitly told otherwise, such as in the discussion leading
386up to sending in the change list, it's better not to specify a reviewer.
387All changes are automatically CC'ed to the
388<a href="https://groups.google.com/group/golang-codereviews">golang-codereviews@googlegroups.com</a>
389mailing list.
390</p>
391
392<p>
393(In Git terms, <code>git</code> <code>mail</code> pushes the local committed
394changes to Gerrit using <code>git</code> <code>push</code> <code>origin</code>
395<code>HEAD:refs/for/master</code>.)
396</p>
Bill Thiede822b2cb2014-07-03 17:42:23 -0400397
398<p>
399If your change relates to an open issue, please add a comment to the issue
400announcing your proposed fix, including a link to your CL.
401</p>
402
Andrew Gerrandd708e922014-12-10 09:29:35 +1100403<p>
404The code review server assigns your change an issue number and URL,
405which <code>git</code> <code>mail</code> will print, something like:
406</p>
407
408<pre>
409remote: New Changes:
410remote: https://go-review.googlesource.com/99999 math: improved Sin, Cos and Tan precision for very large arguments
411</pre>
412
Bill Thiede822b2cb2014-07-03 17:42:23 -0400413<h3>Reviewing code</h3>
414
415<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100416Running <code>git</code> <code>mail</code> will send an email to you and the
417reviewers asking them to visit the issue's URL and make comments on the change.
418When done, the reviewer adds comments through the Gerrit user interface
419and clicks "Reply" to send comments back.
420You will receive a mail notification when this happens.
421You must reply through the web interface.
422(Unlike with the old Rietveld review system, replying by mail has no effect.)
Bill Thiede822b2cb2014-07-03 17:42:23 -0400423</p>
424
Bill Thiede822b2cb2014-07-03 17:42:23 -0400425<h3>Revise and upload</h3>
426
427<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100428You must respond to review comments through the web interface.
429(Unlike with the old Rietveld review system, responding by mail has no effect.)
430</p>
431
432<p>
Bill Thiede822b2cb2014-07-03 17:42:23 -0400433When you have revised the code and are ready for another round of review,
Andrew Gerrandd708e922014-12-10 09:29:35 +1100434stage those changes and use <code>git</code> <code>change</code> to update the
435commit.
436To send the update change list for another round of review,
437run <code>git</code> <code>mail</code> again.
Bill Thiede822b2cb2014-07-03 17:42:23 -0400438</p>
439
440<p>
441The reviewer can comment on the new copy, and the process repeats.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100442The reviewer approves the change by giving it a positive score
443(+1 or +2) and replying <code>LGTM</code>: looks good to me.
Bill Thiede822b2cb2014-07-03 17:42:23 -0400444</p>
445
446<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100447You can see a list of your pending changes by running <code>git</code>
448<code>pending</code>, and switch between change branches with <code>git</code>
449<code>change</code> <code><i>&lt;branch&gt;</i></code>.
Russ Cox38a41ee2009-11-06 10:04:22 -0800450</p>
451
Russ Cox38a41ee2009-11-06 10:04:22 -0800452<h3>Synchronize your client</h3>
453
Andrew Gerrandd708e922014-12-10 09:29:35 +1100454<p>
455While you were working, others might have submitted changes to the repository.
456To update your local branch, run
457</p>
Russ Cox38a41ee2009-11-06 10:04:22 -0800458
459<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100460$ git sync
Russ Cox38a41ee2009-11-06 10:04:22 -0800461</pre>
462
Russ Cox38a41ee2009-11-06 10:04:22 -0800463<p>
Oling Catce365522014-12-14 14:32:56 +0800464(In git terms, <code>git</code> <code>sync</code> runs
Andrew Gerrandd708e922014-12-10 09:29:35 +1100465<code>git</code> <code>pull</code> <code>-r</code>.)
Russ Cox696e8022009-11-07 18:56:00 -0800466</p>
467
468<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100469If files you were editing have changed, Git does its best to merge the
470remote changes into your local changes.
471It may leave some files to merge by hand.
472</p>
473
474<p>
475For example, suppose you have edited <code>sin.go</code> but
Russ Cox696e8022009-11-07 18:56:00 -0800476someone else has committed an independent change.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100477When you run <code>git</code> <code>sync</code>,
478you will get the (scary-looking) output:
Russ Cox38a41ee2009-11-06 10:04:22 -0800479
480<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100481$ git sync
482Failed to merge in the changes.
483Patch failed at 0023 math: improved Sin, Cos and Tan precision for very large arguments
484The copy of the patch that failed is found in:
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800485 /home/you/repo/.git/rebase-apply/patch
Andrew Gerrandd708e922014-12-10 09:29:35 +1100486
487When you have resolved this problem, run "git rebase --continue".
488If you prefer to skip this patch, run "git rebase --skip" instead.
489To check out the original branch and stop rebasing, run "git rebase --abort".
Russ Cox38a41ee2009-11-06 10:04:22 -0800490</pre>
491
Russ Cox696e8022009-11-07 18:56:00 -0800492<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100493If this happens, run
494</p>
495
496<pre>
497$ git status
498</pre>
499
500<p>
501to see which files failed to merge.
502The output will look something like this:
503</p>
504
505<pre>
506rebase in progress; onto a24c3eb
507You are currently rebasing branch 'mcgillicutty' on 'a24c3eb'.
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800508 (fix conflicts and then run "git rebase --continue")
509 (use "git rebase --skip" to skip this patch)
510 (use "git rebase --abort" to check out the original branch)
Andrew Gerrandd708e922014-12-10 09:29:35 +1100511
512Unmerged paths:
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800513 (use "git reset HEAD &lt;file&gt;..." to unstage)
514 (use "git add &lt;file&gt;..." to mark resolution)
Andrew Gerrandd708e922014-12-10 09:29:35 +1100515
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800516 <i>both modified: sin.go</i>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100517</pre>
518
519<p>
520The only important part in that transcript is the italicized "both modified"
521line: Git failed to merge your changes with the conflicting change.
522When this happens, Git leaves both sets of edits in the file,
523with conflicts marked by <code>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</code> and
Russ Cox696e8022009-11-07 18:56:00 -0800524<code>&gt;&gt;&gt;&gt;&gt;&gt;&gt;</code>.
Tetsuo Kiso48347cc2014-07-07 16:31:20 +1000525It is now your job to edit the file to combine them.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100526Continuing the example, searching for those strings in <code>sin.go</code>
Russ Cox696e8022009-11-07 18:56:00 -0800527might turn up:
528</p>
529
530<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100531 arg = scale(arg)
532&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800533 if arg &lt; 1e9 {
Russ Cox696e8022009-11-07 18:56:00 -0800534=======
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800535 if arg &lh; 1e10 {
Andrew Gerrandd708e922014-12-10 09:29:35 +1100536&gt;&gt;&gt;&gt;&gt;&gt;&gt; mcgillicutty
537 largeReduce(arg)
Russ Cox696e8022009-11-07 18:56:00 -0800538</pre>
539
540<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100541Git doesn't show it, but suppose the original text that both edits
542started with was 1e8; you changed it to 1e10 and the other change to 1e9,
543so the correct answer might now be 1e10. First, edit the section
Russ Cox696e8022009-11-07 18:56:00 -0800544to remove the markers and leave the correct code:
545</p>
546
547<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100548 arg = scale(arg)
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800549 if arg &lt; 1e10 {
Andrew Gerrandd708e922014-12-10 09:29:35 +1100550 largeReduce(arg)
Russ Cox696e8022009-11-07 18:56:00 -0800551</pre>
552
553<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100554Then tell Git that the conflict is resolved by running
Russ Cox696e8022009-11-07 18:56:00 -0800555</p>
556
Russ Coxd55abfd2009-12-09 14:05:12 -0800557<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100558$ git add sin.go
Russ Coxd55abfd2009-12-09 14:05:12 -0800559</pre>
560
Russ Cox696e8022009-11-07 18:56:00 -0800561<p>
Russ Cox830813f2009-11-08 21:08:27 -0800562If you had been editing the file, say for debugging, but do not
563care to preserve your changes, you can run
Andrew Gerrandd708e922014-12-10 09:29:35 +1100564<code>git</code> <code>reset</code> <code>HEAD</code> <code>sin.go</code>
565to abandon your changes.
566Then run <code>git</code> <code>rebase</code> <code>--continue</code> to
567restore the change commit.
Russ Cox696e8022009-11-07 18:56:00 -0800568</p>
569
Dave Cheneyeda95902013-02-10 19:40:33 -0500570<h3>Reviewing code by others</h3>
571
572<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100573You can import a change proposed by someone else into your local Git repository.
574On the Gerrit review page, click the "Download ▼" link in the upper right
575corner, copy the "Checkout" command and run it from your local Git repo.
576It should look something like this:
Dave Cheneyeda95902013-02-10 19:40:33 -0500577</p>
578
579<pre>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800580$ git fetch https://go.googlesource.com/review refs/changes/21/1221/1 &amp;&amp; git checkout FETCH_HEAD
Dave Cheneyeda95902013-02-10 19:40:33 -0500581</pre>
582
583<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100584To revert, change back to the branch you were working in.
Oling Cataecbcd02013-02-15 14:01:12 +1100585</p>
Dave Cheneyeda95902013-02-10 19:40:33 -0500586
Russ Cox5facb842009-12-09 14:39:41 -0800587<h3>Submit the change after the review</h3>
Russ Cox38a41ee2009-11-06 10:04:22 -0800588
589<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100590After the code has been <code>LGTM</code>'ed, an approver may
591submit it to the master branch using the Gerrit UI.
592There is a "Submit" button on the web page for the change
593that appears once the change is approved (marked +2).
Dave Cheneyeda95902013-02-10 19:40:33 -0500594</p>
595
596<p>
Russ Cox38a41ee2009-11-06 10:04:22 -0800597This checks the change into the repository.
598The change description will include a link to the code review,
599and the code review will be updated with a link to the change
600in the repository.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100601Since the method used to integrate the changes is "Cherry Pick",
602the commit hashes in the repository will be changed by
603the submit operation.
Russ Cox38a41ee2009-11-06 10:04:22 -0800604</p>
605
Robert Hencke75ba1812014-04-25 20:09:04 -0700606<h3>More information</h3>
607
608<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100609In addition to the information here, the Go community maintains a <a href="https://golang.org/wiki/CodeReview">CodeReview</a> wiki page.
Robert Hencke75ba1812014-04-25 20:09:04 -0700610Feel free to contribute to this page as you learn the review process.
611</p>
612
Dave Cheneyeda95902013-02-10 19:40:33 -0500613<h2 id="copyright">Copyright</h2>
Russ Cox38a41ee2009-11-06 10:04:22 -0800614
Russ Coxd55abfd2009-12-09 14:05:12 -0800615<p>Files in the Go repository don't list author names,
616both to avoid clutter and to avoid having to keep the lists up to date.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100617Instead, your name will appear in the
618<a href="https://golang.org/change">change log</a>
Russ Coxd55abfd2009-12-09 14:05:12 -0800619and in the <a href="/CONTRIBUTORS"><code>CONTRIBUTORS</code></a> file
620and perhaps the <a href="/AUTHORS"><code>AUTHORS</code></a> file.
621</p>
622
623<p>The <a href="/CONTRIBUTORS"><code>CONTRIBUTORS</code></a> file
624defines who the Go contributors&mdash;the people&mdash;are;
Caleb Spare41f32e02013-01-06 22:44:16 -0500625the <a href="/AUTHORS"><code>AUTHORS</code></a> file defines
Russ Coxd55abfd2009-12-09 14:05:12 -0800626who &ldquo;The Go Authors&rdquo;&mdash;the copyright holders&mdash;are.
Dmitry Savintsev30ab39a2015-06-09 12:01:38 +0200627These files will be periodically updated based on the commit logs.
628
629<p>Gerrit serves as the gatekeeper and uses your e-mail address as the key.
630To send your first change to the Go project from a given address,
631you must have completed one of the contributor license agreements:
Russ Coxd55abfd2009-12-09 14:05:12 -0800632<ul>
633<li>
Brad Fitzpatrick967901a2014-03-05 14:09:03 -0800634If you are the copyright holder, you will need to agree to the
635<a href="https://developers.google.com/open-source/cla/individual">individual
Russ Coxd55abfd2009-12-09 14:05:12 -0800636contributor license agreement</a>, which can be completed online.
637</li>
638<li>
639If your organization is the copyright holder, the organization
Brad Fitzpatrick967901a2014-03-05 14:09:03 -0800640will need to agree to the
641<a href="https://developers.google.com/open-source/cla/corporate">corporate
642contributor license agreement</a>.
Russ Coxd55abfd2009-12-09 14:05:12 -0800643(If the copyright holder for your code has already completed the
644agreement in connection with another Google open source project,
645it does not need to be completed again.)
646</li>
647</ul>
648
649<p>
650This rigmarole needs to be done only for your first submission.
651</p>
652
653<p>Code that you contribute should use the standard copyright header:</p>
Russ Cox38a41ee2009-11-06 10:04:22 -0800654
655<pre>
David Symonds6cb40332015-01-01 00:00:00 +1100656// Copyright 2015 The Go Authors. All rights reserved.
Russ Cox38a41ee2009-11-06 10:04:22 -0800657// Use of this source code is governed by a BSD-style
658// license that can be found in the LICENSE file.
659</pre>
Dave Cheneyeda95902013-02-10 19:40:33 -0500660
661<p>
662Files in the repository are copyright the year they are added. It is not
663necessary to update the copyright year on files that you change.
664</p>