contribute.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. <!--{
  2. "Title": "Contribution Guide"
  3. }-->
  4. <p>
  5. The Go project welcomes all contributors. The process of contributing
  6. to the Go project may be different than many projects you are used to.
  7. This document is intended as a guide to help you through the contribution
  8. process. This guide assumes you have a basic understanding of Git and Go.
  9. </p>
  10. <p>
  11. (Note that the <code>gccgo</code> frontend lives elsewhere;
  12. see <a href="gccgo_contribute.html">Contributing to gccgo</a>.)
  13. </p>
  14. <p>
  15. Sensitive security-related issues should be reported to <a href="mailto:security@golang.org">security@golang.org</a>.
  16. </p>
  17. <h1 id="contributor">Becoming a contributor</h1>
  18. <p>
  19. Before you can contribute to the Go project you need to setup a few prerequisites.
  20. The Go project uses <a href="https://www.gerritcodereview.com/">Gerrit</a>, an open
  21. source online tool, to perform all code reviews.
  22. Gerrit uses your email address as a unique identifier.
  23. The Go project contributing flow is currently configured to work only with Google Accounts.
  24. You must go through the following process <em>prior to contributing</em>.
  25. You only need to do this once per Google Account.
  26. </p>
  27. <h2 id="go-contrib-init">Automatically set up &amp; diagnose your development environment</h3>
  28. <p>
  29. The <code>go-contrib-init</code> tool configures and debugs your Go
  30. development environment, automatically performing many of the steps
  31. on this page, or telling you what you need to do next. If you wish
  32. to use it, run:
  33. </p>
  34. <pre>
  35. $ go get -u golang.org/x/tools/cmd/go-contrib-init
  36. $ cd /code/to/edit
  37. $ go-contrib-init
  38. </pre>
  39. <p>
  40. The tool will either set things up, tell you that everything is
  41. configured, or tell you what steps you need to do manually.
  42. </p>
  43. <h2 id="auth">Configure Git to use Gerrit</h2>
  44. <p>
  45. You'll need a web browser and a command line terminal.
  46. You should already have Git installed.
  47. </p>
  48. <p>
  49. Gerrit uses Google Accounts for authentication.
  50. If you don't have a Google Account, you can create an account which
  51. <a href="https://www.google.com/accounts/NewAccount">includes
  52. a new Gmail email account</a> or create an account associated
  53. <a href="https://accounts.google.com/SignUpWithoutGmail">with your existing
  54. email address</a>.
  55. </p>
  56. <h3>Step 1: Sign in to googlesource and generate a password</h3>
  57. <p>
  58. Visit <a href="https://go.googlesource.com">go.googlesource.com</a>
  59. and click on "Generate Password" in the page's top right menu bar.
  60. You will be redirected to accounts.google.com to sign in.
  61. </p>
  62. <h3>Step 2: Run the provided script</h3>
  63. <p>
  64. After signing in, you are taken to a page on go.googlesource.com with the title "Configure Git".
  65. This page contains a personalized script which when run locally will configure git
  66. to have your unique authentication key.
  67. This key is paired with one generated server side similar to how ssh keys work.
  68. </p>
  69. <p>
  70. Copy and run this script locally in your command line terminal.
  71. (On a Windows computer using cmd you should instead follow the instructions
  72. in the yellow box to run the command. If you are using git-bash use the same
  73. script as *nix.)
  74. </p>
  75. <p>
  76. Your secret authentication token is now in a <code>.gitcookie</code> file
  77. and Git is configured to use this file.
  78. </p>
  79. <h3 id="gerrit">Step 3: Register with Gerrit</h3>
  80. <p>
  81. Now that you have your authentication token, you need to register your
  82. account with Gerrit.
  83. To do this, visit <a href="https://go-review.googlesource.com/login/">
  84. go-review.googlesource.com/login/</a>.
  85. Sign in using the same Google Account you used above.
  86. </p>
  87. <h2 id="cla">Contributor License Agreement</h2>
  88. <h3 id="which_cla">Which CLA</h3>
  89. <p>
  90. Before sending your first change to the Go project
  91. you must have completed one of the following two CLAs.
  92. Which CLA you should sign depends on who owns the copyright to your work.
  93. </p>
  94. <ul>
  95. <li>
  96. If you are the copyright holder, you will need to agree to the
  97. <a href="https://developers.google.com/open-source/cla/individual">individual
  98. contributor license agreement</a>, which can be completed online.
  99. </li>
  100. <li>
  101. If your organization is the copyright holder, the organization
  102. will need to agree to the
  103. <a href="https://developers.google.com/open-source/cla/corporate">corporate
  104. contributor license agreement</a>.<br>
  105. </li>
  106. </ul>
  107. <p>
  108. <i>If the copyright holder for your contribution has already completed the
  109. agreement in connection with another Google open source project,
  110. it does not need to be completed again.</i>
  111. </p>
  112. <h3 id="signing_cla">Completing the CLA</h3>
  113. <p>
  114. You can see your currently signed agreements and sign new ones through the Gerrit
  115. interface.
  116. To do this, <a href="https://go-review.googlesource.com/login/">Log into Gerrit</a>,
  117. then visit the <a href="https://go-review.googlesource.com/settings/agreements">Agreements</a>
  118. page.
  119. If you do not have a signed agreement listed there, you can create one
  120. by clicking "New Contributor Agreement" and following the steps.
  121. </p>
  122. <p>
  123. If the copyright holder for the code you are submitting changes &mdash; for example,
  124. if you start contributing code on behalf of a new company &mdash; please send email
  125. to golang-dev and let us know, so that we can make sure an appropriate agreement is
  126. completed and update the <code>AUTHORS</code> file.
  127. </p>
  128. <span id="Code_review"></span>
  129. <h1 id="prepare_dev_env">Preparing a Development Environment for Contributing</h1>
  130. <h2 id="git-codereview">Setting up Git for submission to Gerrit</h2>
  131. <p>
  132. Changes to Go must be reviewed before they are accepted, no matter who makes the change.
  133. A custom git command called <code>git-codereview</code>, discussed below,
  134. helps manage the code review process through a Google-hosted
  135. <a href="https://go-review.googlesource.com/">instance</a> Gerrit.
  136. </p>
  137. <h3 id="git-codereview_install">Install the git-codereview command</h3>
  138. <p>
  139. Install the <code>git-codereview</code> command by running,
  140. </p>
  141. <pre>
  142. $ go get -u golang.org/x/review/git-codereview
  143. </pre>
  144. <p>
  145. Make sure <code>git-codereview</code> is installed in your shell path, so that the
  146. <code>git</code> command can find it. Check that
  147. </p>
  148. <pre>
  149. $ git codereview help
  150. </pre>
  151. <p>
  152. prints help text, not an error.
  153. </p>
  154. <p>
  155. On Windows, when using git-bash you must make sure that
  156. <code>git-codereview.exe</code> is in your git exec-path.
  157. Run <code>git --exec-path</code> to discover the right location then create a
  158. symbolic link or simply copy the executible from $GOPATH/bin to this directory.
  159. </p>
  160. <p>
  161. <b>Note to Git aficionados:</b>
  162. The <code>git-codereview</code> command is not required to
  163. upload and manage Gerrit code reviews.
  164. For those who prefer plain Git, the text below gives the Git equivalent of
  165. each git-codereview command.
  166. </p>
  167. <p>
  168. If you do use plain Git, note that you still need the commit hooks that the
  169. git-codereview command configures; those hooks add a Gerrit
  170. <code>Change-Id</code> line to the commit message and check that all Go source
  171. files have been formatted with gofmt.
  172. Even if you intend to use plain Git for
  173. daily work, install the hooks in a new Git checkout by running
  174. <code>git-codereview</code> <code>hooks</code>.
  175. </p>
  176. <p>
  177. The workflow described below assumes a single change per branch.
  178. It is also possible to prepare a sequence of (usually related) changes in a single branch.
  179. See the <a href="https://golang.org/x/review/git-codereview">git-codereview documentation</a> for details.
  180. </p>
  181. <h3 id="git-config">Set up git aliases</h3>
  182. <p>
  183. The <code>git-codereview</code> command can be run directly from the shell
  184. by typing, for instance,
  185. </p>
  186. <pre>
  187. $ git codereview sync
  188. </pre>
  189. <p>
  190. but it is more convenient to set up aliases for <code>git-codereview</code>'s own
  191. subcommands, so that the above becomes,
  192. </p>
  193. <pre>
  194. $ git sync
  195. </pre>
  196. <p>
  197. The <code>git-codereview</code> subcommands have been chosen to be distinct from
  198. Git's own, so it's safe to do so.
  199. </p>
  200. <p>
  201. The aliases are optional, but in the rest of this document we will assume
  202. they are installed.
  203. To install them, copy this text into your Git configuration file
  204. (usually <code>.gitconfig</code> in your home directory):
  205. </p>
  206. <pre>
  207. [alias]
  208. change = codereview change
  209. gofmt = codereview gofmt
  210. mail = codereview mail
  211. pending = codereview pending
  212. submit = codereview submit
  213. sync = codereview sync
  214. </pre>
  215. <span id="help"></span>
  216. <h3 id="understanding_git-codereview">Understanding the git-codereview command</h3>
  217. <p>After installing the <code>git-codereview</code> command, you can run</p>
  218. <pre>
  219. $ git codereview help
  220. </pre>
  221. <p>
  222. to learn more about its commands.
  223. You can also read the <a href="https://godoc.org/golang.org/x/review/git-codereview">command documentation</a>.
  224. </p>
  225. <h1 id="making_a_contribution">Making a Contribution</h1>
  226. <h2 id="Design">Discuss your design</h2>
  227. <p>
  228. The project welcomes submissions but please let everyone know what
  229. you're working on if you want to change or add to the Go repositories.
  230. </p>
  231. <p>
  232. Before undertaking to write something new for the Go project,
  233. please <a href="https://golang.org/issue/new">file an issue</a>
  234. (or claim an <a href="https://golang.org/issues">existing issue</a>).
  235. Significant changes must go through the
  236. <a href="https://golang.org/s/proposal-process">change proposal process</a>
  237. before they can be accepted.
  238. </p>
  239. <p>
  240. This process gives everyone a chance to validate the design,
  241. helps prevent duplication of effort,
  242. and ensures that the idea fits inside the goals for the language and tools.
  243. It also checks that the design is sound before code is written;
  244. the code review tool is not the place for high-level discussions.
  245. </p>
  246. <p>
  247. When planning work, please note that the Go project follows a <a
  248. href="https://golang.org/wiki/Go-Release-Cycle">six-month development cycle</a>.
  249. The latter half of each cycle is a three-month feature freeze during
  250. which only bug fixes and doc updates are accepted. New contributions can be
  251. sent during a feature freeze but will not be accepted until the freeze thaws.
  252. </p>
  253. <h2 id="making_a_change">Making a change</h2>
  254. <h3 id="checkout_go">Getting Go Source</h3>
  255. <p>
  256. First you need to have a local copy of the source checked out from the correct
  257. repository.
  258. As Go builds Go you will also likely need to have a working version
  259. of Go installed (some documentation changes may not need this).
  260. This should be a recent version of Go and can be obtained via any package or
  261. binary distribution or you can build it from source.
  262. </p>
  263. <p>
  264. You should checkout the Go source repo anywhere you want as long as it's
  265. outside of your $GOPATH.
  266. Go to a directory where you want the source to appear and run the following
  267. command in a terminal.
  268. </p>
  269. <pre>
  270. $ git clone https://go.googlesource.com/go
  271. $ cd go
  272. </pre>
  273. <h3 id="master">Contributing to the main Go tree</h3>
  274. <p>
  275. Most Go installations use a release branch, but new changes should
  276. only be made based on the master branch. <br>
  277. (They may be applied later to a release branch as part of the release process,
  278. but most contributors won't do this themselves.)
  279. Before making a change, make sure you start on the master branch:
  280. </p>
  281. <pre>
  282. $ git checkout master
  283. $ git sync
  284. </pre>
  285. <p>
  286. (In Git terms, <code>git</code> <code>sync</code> runs
  287. <code>git</code> <code>pull</code> <code>-r</code>.)
  288. </p>
  289. <h3 id="subrepos">Contributing to subrepositories (golang.org/x/...)</h3>
  290. <p>
  291. If you are contributing a change to a subrepository, obtain the
  292. Go package using <code>go get</code>. For example, to contribute
  293. to <code>golang.org/x/oauth2</code>, check out the code by running:
  294. </p>
  295. <pre>
  296. $ go get -d golang.org/x/oauth2/...
  297. </pre>
  298. <p>
  299. Then, change your directory to the package's source directory
  300. (<code>$GOPATH/src/golang.org/x/oauth2</code>).
  301. </p>
  302. <h3 id="change">Make your changes</h3>
  303. <p>
  304. The entire checked-out tree is editable.
  305. Make your changes as you see fit ensuring that you create appropriate
  306. tests along with your changes. Test your changes as you go.
  307. </p>
  308. <h3 id="copyright">Copyright</h3>
  309. <p>
  310. Files in the Go repository don't list author names, both to avoid clutter
  311. and to avoid having to keep the lists up to date.
  312. Instead, your name will appear in the
  313. <a href="https://golang.org/change">change log</a> and in the <a
  314. href="/CONTRIBUTORS"><code>CONTRIBUTORS</code></a> file and perhaps the <a
  315. href="/AUTHORS"><code>AUTHORS</code></a> file.
  316. These files are automatically generated from the commit logs perodically.
  317. The <a href="/AUTHORS"><code>AUTHORS</code></a> file defines who &ldquo;The Go
  318. Authors&rdquo;&mdash;the copyright holders&mdash;are.
  319. </p>
  320. <p>New files that you contribute should use the standard copyright header:</p>
  321. <pre>
  322. // Copyright 2017 The Go Authors. All rights reserved.
  323. // Use of this source code is governed by a BSD-style
  324. // license that can be found in the LICENSE file.
  325. </pre>
  326. <p>
  327. Files in the repository are copyright the year they are added.
  328. Do not update the copyright year on files that you change.
  329. </p>
  330. <h3 id="commit_changes">Commit your changes</h3>
  331. <p>
  332. Once you have edited files, you must tell Git that they have been modified.
  333. You must also tell Git about any files that are added, removed, or renamed files.
  334. These operations are done with the usual Git commands,
  335. <code>git</code> <code>add</code>,
  336. <code>git</code> <code>rm</code>,
  337. and
  338. <code>git</code> <code>mv</code>.
  339. </p>
  340. <p>
  341. Once you have the changes queued up, you will want to commit them.
  342. In the Go contribution workflow this is done with a <code>git</code>
  343. <code>change</code> command, which creates a local branch and commits the changes
  344. directly to that local branch.
  345. </p>
  346. <pre>
  347. $ git change <i>&lt;branch&gt;</i>
  348. </pre>
  349. <p>
  350. The name <i>&lt;branch&gt;</i> is an arbitrary one you choose to identify the
  351. local branch containing your changes and will not be used elsewhere.
  352. This is an offline operation and nothing will be sent to the server yet.
  353. </p>
  354. <p>
  355. (In Git terms, <code>git</code> <code>change</code> <code>&lt;branch&gt;</code>
  356. runs <code>git</code> <code>checkout</code> <code>-b</code> <code>branch</code>,
  357. then <code>git</code> <code>branch</code> <code>--set-upstream-to</code> <code>origin/master</code>,
  358. then <code>git</code> <code>commit</code>.)
  359. </p>
  360. <p>
  361. As the <code>git</code> <code>commit</code> is the final step, Git will open an
  362. editor to ask for a commit message. (It uses the editor named by
  363. the <code>$EDITOR</code> environment variable,
  364. <code>vi</code> by default.)
  365. The file will look like:
  366. </p>
  367. <pre>
  368. # Please enter the commit message for your changes. Lines starting
  369. # with '#' will be ignored, and an empty message aborts the commit.
  370. # On branch foo
  371. # Changes not staged for commit:
  372. # modified: editedfile.go
  373. #
  374. </pre>
  375. <p>
  376. At the beginning of this file is a blank line; replace it
  377. with a thorough description of your change.
  378. The first line of the change description is conventionally a one-line
  379. summary of the change, prefixed by the primary affected package,
  380. and is used as the subject for code review email.
  381. It should complete the sentence "This change modifies Go to _____."
  382. The rest of the description elaborates and should provide context for the
  383. change and explain what it does.
  384. Write in complete sentences with correct punctuation, just like
  385. for your comments in Go.
  386. If there is a helpful reference, mention it here.
  387. If you've fixed an issue, reference it by number with a # before it.
  388. </p>
  389. <p>
  390. After editing, the template might now read:
  391. </p>
  392. <pre>
  393. math: improve Sin, Cos and Tan precision for very large arguments
  394. The existing implementation has poor numerical properties for
  395. large arguments, so use the McGillicutty algorithm to improve
  396. accuracy above 1e10.
  397. The algorithm is described at http://wikipedia.org/wiki/McGillicutty_Algorithm
  398. Fixes #159
  399. # Please enter the commit message for your changes. Lines starting
  400. # with '#' will be ignored, and an empty message aborts the commit.
  401. # On branch foo
  402. # Changes not staged for commit:
  403. # modified: editedfile.go
  404. #
  405. </pre>
  406. <p>
  407. The commented section of the file lists all the modified files in your client.
  408. It is best to keep unrelated changes in different commits,
  409. so if you see a file listed that should not be included, abort
  410. the command and move that file to a different branch.
  411. </p>
  412. <p>
  413. The special notation "Fixes #159" associates the change with issue 159 in the
  414. <a href="https://golang.org/issue/159">Go issue tracker</a>.
  415. When this change is eventually applied, the issue
  416. tracker will automatically mark the issue as fixed.
  417. (There are several such conventions, described in detail in the
  418. <a href="https://help.github.com/articles/closing-issues-via-commit-messages/">GitHub Issue Tracker documentation</a>.)
  419. </p>
  420. <p>
  421. Once you have finished writing the commit message,
  422. save the file and exit the editor.
  423. </p>
  424. <p>
  425. You must have the $EDITOR environment variable set properly and working properly (exiting cleanly)
  426. for this operation to succeed.
  427. If you run into any issues at this step, it's likely your editor isn't exiting cleanly.
  428. Try setting a different editor in your $EDITOR environment variable.
  429. </p>
  430. <p>
  431. If you wish to do more editing, re-stage your changes using
  432. <code>git</code> <code>add</code>, and then run
  433. </p>
  434. <pre>
  435. $ git change
  436. </pre>
  437. <p>
  438. to update the change description and incorporate the staged changes.
  439. The change description contains a <code>Change-Id</code> line near the bottom,
  440. added by a Git commit hook during the initial
  441. <code>git</code> <code>change</code>.
  442. That line is used by Gerrit to match successive uploads of the same change.
  443. Do not edit or delete it.
  444. </p>
  445. <p>
  446. (In Git terms, <code>git</code> <code>change</code> with no branch name
  447. runs <code>git</code> <code>commit</code> <code>--amend</code>.)
  448. </p>
  449. <h3 id="Testing">Testing</h3>
  450. <p>
  451. You've <a href="code.html">written and tested your code</a>, but
  452. before sending code out for review, run all the tests for the whole
  453. tree to make sure the changes don't break other packages or programs:
  454. </p>
  455. <pre>
  456. $ cd go/src
  457. $ ./all.bash
  458. </pre>
  459. <p>
  460. (To build under Windows use <code>all.bat</code>.)
  461. </p>
  462. <p>
  463. After running for a while, the command should print
  464. </p>
  465. <pre>
  466. "ALL TESTS PASSED".
  467. </pre>
  468. <h3 id="mail">Send the change for review</h3>
  469. <p>
  470. Once the change is ready, send it for review.
  471. This is similar to a <code>git push</code> in a GitHub style workflow.
  472. This is done via the mail alias setup earlier which despite its name, doesn't
  473. directly mail anything, it simply sends the change to Gerrit via git push.
  474. </p>
  475. <pre>
  476. $ git mail
  477. </pre>
  478. <p>
  479. (In Git terms, <code>git</code> <code>mail</code> pushes the local committed
  480. changes to Gerrit using <code>git</code> <code>push</code> <code>origin</code>
  481. <code>HEAD:refs/for/master</code>.)
  482. </p>
  483. <p>
  484. If your change relates to an open issue, please add a comment to the issue
  485. announcing your proposed fix, including a link to your change.
  486. </p>
  487. <p>
  488. The code review server assigns your change an issue number and URL,
  489. which <code>git</code> <code>mail</code> will print, something like:
  490. </p>
  491. <pre>
  492. remote: New Changes:
  493. remote: https://go-review.googlesource.com/99999 math: improved Sin, Cos and Tan precision for very large arguments
  494. </pre>
  495. <h3>Troubleshooting</h3>
  496. <p>
  497. The most common way that the <code>git mail</code> command fails is because the
  498. email address used has not gone through the setup above.
  499. <br>
  500. If you see something like...
  501. </p>
  502. <pre>
  503. remote: Processing changes: refs: 1, done
  504. remote:
  505. remote: ERROR: In commit ab13517fa29487dcf8b0d48916c51639426c5ee9
  506. remote: ERROR: author email address XXXXXXXXXXXXXXXXXXX
  507. remote: ERROR: does not match your user account.
  508. </pre>
  509. <p>
  510. You need to either add the email address listed to the CLA or set this repo to use
  511. another email address already approved.
  512. </p>
  513. <p>
  514. First let's change the email address for this repo so this doesn't happen again.
  515. You can change your email address for this repo with the following command:
  516. </p>
  517. <pre>
  518. $ git config user.email email@address.com
  519. </pre>
  520. <p>
  521. Then change the previous commit to use this alternative email address.
  522. You can do that with:
  523. </p>
  524. <pre>
  525. $ git commit --amend --author="Author Name &lt;email@address.com&gt;"
  526. </pre>
  527. <p>
  528. Finally try to resend with:
  529. </p>
  530. <pre>
  531. $ git mail
  532. </pre>
  533. <h3 id="cc">Specifying a reviewer / CCing others</h3>
  534. <p>
  535. Unless explicitly told otherwise, such as in the discussion leading
  536. up to sending in the change, it's better not to specify a reviewer.
  537. All changes are automatically CC'ed to the
  538. <a href="https://groups.google.com/group/golang-codereviews">golang-codereviews@googlegroups.com</a>
  539. mailing list. If this is your first ever change, there may be a moderation
  540. delay before it appears on the mailing list, to prevent spam.
  541. </p>
  542. <p>
  543. You can specify a reviewer or CC interested parties
  544. using the <code>-r</code> or <code>-cc</code> options.
  545. Both accept a comma-separated list of email addresses:
  546. </p>
  547. <pre>
  548. $ git mail -r joe@golang.org -cc mabel@example.com,math-nuts@swtch.com
  549. </pre>
  550. <h2 id="review">Going through the review process</h2>
  551. <p>
  552. Running <code>git</code> <code>mail</code> will send an email to you and the
  553. reviewers asking them to visit the issue's URL and make comments on the change.
  554. When done, the reviewer adds comments through the Gerrit user interface
  555. and clicks "Reply" to send comments back.
  556. You will receive a mail notification when this happens.
  557. You must reply through the web interface.
  558. (Unlike with the old Rietveld review system, replying by mail has no effect.)
  559. </p>
  560. <h3 id="revise">Revise and resend</h3>
  561. <p>
  562. The Go contribution workflow is optimized for iterative revisions based on
  563. feedback.
  564. It is rare that an initial contribution will be ready to be applied as is.
  565. As you revise your contribution and resend Gerrit will retain a history of
  566. all the changes and comments made in the single URL.
  567. </p>
  568. <p>
  569. You must respond to review comments through the web interface.
  570. (Unlike with the old Rietveld review system, responding by mail has no effect.)
  571. </p>
  572. <p>
  573. When you have revised the code and are ready for another round of review,
  574. stage those changes and use <code>git</code> <code>change</code> to update the
  575. commit.
  576. To send the updated change for another round of review,
  577. run <code>git</code> <code>mail</code> again.
  578. </p>
  579. <p>
  580. The reviewer can comment on the new copy, and the process repeats.
  581. The reviewer approves the change by giving it a positive score
  582. (+1 or +2) and replying <code>LGTM</code>: looks good to me.
  583. </p>
  584. <p>
  585. You can see a list of your pending changes by running <code>git</code>
  586. <code>pending</code>, and switch between change branches with <code>git</code>
  587. <code>change</code> <code><i>&lt;branch&gt;</i></code>.
  588. </p>
  589. <h3 id="sync">Synchronize your client</h3>
  590. <p>
  591. While you were working, others might have submitted changes to the repository.
  592. To update your local branch, run
  593. </p>
  594. <pre>
  595. $ git sync
  596. </pre>
  597. <p>
  598. (In git terms, <code>git</code> <code>sync</code> runs
  599. <code>git</code> <code>pull</code> <code>-r</code>.)
  600. </p>
  601. <h3 id="resolving_conflicts">Resolving Conflicts</h3>
  602. <p>
  603. If files you were editing have changed, Git does its best to merge the
  604. remote changes into your local changes.
  605. It may leave some files to merge by hand.
  606. </p>
  607. <p>
  608. For example, suppose you have edited <code>sin.go</code> but
  609. someone else has committed an independent change.
  610. When you run <code>git</code> <code>sync</code>,
  611. you will get the (scary-looking) output:
  612. <pre>
  613. $ git sync
  614. Failed to merge in the changes.
  615. Patch failed at 0023 math: improved Sin, Cos and Tan precision for very large arguments
  616. The copy of the patch that failed is found in:
  617. /home/you/repo/.git/rebase-apply/patch
  618. When you have resolved this problem, run "git rebase --continue".
  619. If you prefer to skip this patch, run "git rebase --skip" instead.
  620. To check out the original branch and stop rebasing, run "git rebase --abort".
  621. </pre>
  622. <p>
  623. If this happens, run
  624. </p>
  625. <pre>
  626. $ git status
  627. </pre>
  628. <p>
  629. to see which files failed to merge.
  630. The output will look something like this:
  631. </p>
  632. <pre>
  633. rebase in progress; onto a24c3eb
  634. You are currently rebasing branch 'mcgillicutty' on 'a24c3eb'.
  635. (fix conflicts and then run "git rebase --continue")
  636. (use "git rebase --skip" to skip this patch)
  637. (use "git rebase --abort" to check out the original branch)
  638. Unmerged paths:
  639. (use "git reset HEAD &lt;file&gt;..." to unstage)
  640. (use "git add &lt;file&gt;..." to mark resolution)
  641. <i>both modified: sin.go</i>
  642. </pre>
  643. <p>
  644. The only important part in that transcript is the italicized "both modified"
  645. line: Git failed to merge your changes with the conflicting change.
  646. When this happens, Git leaves both sets of edits in the file,
  647. with conflicts marked by <code>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</code> and
  648. <code>&gt;&gt;&gt;&gt;&gt;&gt;&gt;</code>.
  649. It is now your job to edit the file to combine them.
  650. Continuing the example, searching for those strings in <code>sin.go</code>
  651. might turn up:
  652. </p>
  653. <pre>
  654. arg = scale(arg)
  655. &lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD
  656. if arg &lt; 1e9 {
  657. =======
  658. if arg &lt; 1e10 {
  659. &gt;&gt;&gt;&gt;&gt;&gt;&gt; mcgillicutty
  660. largeReduce(arg)
  661. </pre>
  662. <p>
  663. Git doesn't show it, but suppose the original text that both edits
  664. started with was 1e8; you changed it to 1e10 and the other change to 1e9,
  665. so the correct answer might now be 1e10.
  666. First, edit the section to remove the markers and leave the correct code:
  667. </p>
  668. <pre>
  669. arg = scale(arg)
  670. if arg &lt; 1e10 {
  671. largeReduce(arg)
  672. </pre>
  673. <p>
  674. Then tell Git that the conflict is resolved by running
  675. </p>
  676. <pre>
  677. $ git add sin.go
  678. </pre>
  679. <p>
  680. If you had been editing the file, say for debugging, but do not
  681. care to preserve your changes, you can run
  682. <code>git</code> <code>reset</code> <code>HEAD</code> <code>sin.go</code>
  683. to abandon your changes.
  684. Then run <code>git</code> <code>rebase</code> <code>--continue</code> to
  685. restore the change commit.
  686. </p>
  687. <h3 id="download">Reviewing code by others</h3>
  688. <p>
  689. As part of the review process reviewers can propose changes directly (in the
  690. GitHub workflow this would be someone else attaching commits to a pull request).
  691. You can import these changes proposed by someone else into your local Git repository.
  692. On the Gerrit review page, click the "Download ▼" link in the upper right
  693. corner, copy the "Checkout" command and run it from your local Git repo. It
  694. should look something like this:
  695. </p>
  696. <pre>
  697. $ git fetch https://go.googlesource.com/review refs/changes/21/1221/1 &amp;&amp; git checkout FETCH_HEAD
  698. </pre>
  699. <p>
  700. To revert, change back to the branch you were working in.
  701. </p>
  702. <h2 id="submit">Apply the change to the master branch</h2>
  703. <p>
  704. After the code has been <code>LGTM</code>'ed, an approver may
  705. apply it to the master branch using the Gerrit UI.
  706. There is a "Submit" button on the web page for the change
  707. that appears once the change is approved (marked +2).
  708. </p>
  709. <p>
  710. This checks the change into the repository.
  711. The change description will include a link to the code review,
  712. and the code review will be updated with a link to the change
  713. in the repository.
  714. Since the method used to integrate the changes is "Cherry Pick",
  715. the commit hashes in the repository will be changed by
  716. the "Submit" operation.
  717. </p>
  718. <h2 id="more">More information</h2>
  719. <p>
  720. In addition to the information here, the Go community maintains a <a
  721. href="https://golang.org/wiki/CodeReview">CodeReview</a> wiki page.
  722. Feel free to contribute to this page as you learn the review process.
  723. </p>