github.com/slayercat/go@v0.0.0-20170428012452-c51559813f61/doc/contribute.html (about)

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