{"title":"使用 Git 和 GitHub 工作","version":"3.1","locale":"zh-hans","docname":"internals/contributing/writing-code/working-with-git","url":"/zh-hans/3.1/internals/contributing/writing-code/working-with-git/","canonical":"https://djangodocs.dev/zh-hans/3.1/internals/contributing/writing-code/working-with-git/","summary":"This section explains how the community can contribute code to Django via pull requests. If you're interested in how committers handle them, see 提交代码 . Below, we…","html":"<h1>使用 Git 和 GitHub 工作<a class=\"heading-anchor\" href=\"#working-with-git-and-github\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>This section explains how the community can contribute code to Django via pull\nrequests. If you're interested in how committers handle them, see\n<a class=\"reference internal\" href=\"/zh-hans/3.1/internals/contributing/committing-code/\"><span class=\"doc\">提交代码</span></a>.</p>\n<p>Below, we are going to show how to create a GitHub pull request containing the\nchanges for Trac ticket #xxxxx. By creating a fully-ready pull request, you\nwill make the reviewer's job easier, meaning that your work is more likely to\nbe merged into Django.</p>\n<p>您也可以将传统的补丁程序上传到 Trac ，但对于评论来说不太实用。</p>\n<section id=\"installing-git\">\n<h2>安装 Git<a class=\"heading-anchor\" href=\"#installing-git\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django uses <a class=\"reference external\" href=\"https://git-scm.com/\">Git</a> for its source control. You can <a class=\"reference external\" href=\"https://git-scm.com/download\">download</a> Git, but it's often easier to install with\nyour operating system's package manager.</p>\n<p>Django的 <a class=\"reference external\" href=\"https://github.com/django/django/\">Git 仓库</a>  托管在  <a class=\"reference external\" href=\"https://github.com/\">GitHub</a> 上，建议您也使用GitHub。</p>\n<p>After installing Git, the first thing you should do is setup your name and\nemail:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>$ git config --global user.name &quot;Your Real Name&quot;\n$ git config --global user.email &quot;you@email.com&quot;\n</code></pre></div>\n<p>请注意， <code class=\"docutils literal notranslate\"><span class=\"pre\">user.name</span></code> 应该是您的真实姓名，而不是您的GitHub昵称。 GitHub应该知道您在 <code class=\"docutils literal notranslate\"><span class=\"pre\">user.email</span></code> 字段中使用的电子邮件，因为这将用于将提交与GitHub账户相关联。</p>\n</section>\n<section id=\"setting-up-local-repository\">\n<h2>设置本地仓库<a class=\"heading-anchor\" href=\"#setting-up-local-repository\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>When you have created your GitHub account, with the nick &quot;GitHub_nick&quot;, and\n<a class=\"reference external\" href=\"https://github.com/django/django/fork\">forked Django's repository</a>,\ncreate a local copy of your fork:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">git</span> <span class=\"n\">clone</span> <span class=\"n\">https</span><span class=\"p\">:</span><span class=\"o\">//</span><span class=\"n\">github</span><span class=\"o\">.</span><span class=\"n\">com</span><span class=\"o\">/</span><span class=\"n\">GitHub_nick</span><span class=\"o\">/</span><span class=\"n\">django</span><span class=\"o\">.</span><span class=\"n\">git</span>\n</code></pre></div>\n<p>This will create a new directory &quot;django&quot;, containing a clone of your GitHub\nrepository. The rest of the git commands on this page need to be run within the\ncloned directory, so switch to it now:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">cd</span> <span class=\"n\">django</span>\n</code></pre></div>\n<p>在 Git 中，你的 Github 仓库会被称做“origin”。</p>\n<p>You should also setup <code class=\"docutils literal notranslate\"><span class=\"pre\">django/django</span></code> as an &quot;upstream&quot; remote (that is, tell\ngit that the reference Django repository was the source of your fork of it):</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">git</span> <span class=\"n\">remote</span> <span class=\"n\">add</span> <span class=\"n\">upstream</span> <span class=\"n\">git</span><span class=\"nd\">@github</span><span class=\"o\">.</span><span class=\"n\">com</span><span class=\"p\">:</span><span class=\"n\">django</span><span class=\"o\">/</span><span class=\"n\">django</span><span class=\"o\">.</span><span class=\"n\">git</span>\n<span class=\"n\">git</span> <span class=\"n\">fetch</span> <span class=\"n\">upstream</span>\n</code></pre></div>\n<p>您可以类似地添加其他远程仓库，例如：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">git</span> <span class=\"n\">remote</span> <span class=\"n\">add</span> <span class=\"n\">akaariai</span> <span class=\"n\">git</span><span class=\"nd\">@github</span><span class=\"o\">.</span><span class=\"n\">com</span><span class=\"p\">:</span><span class=\"n\">akaariai</span><span class=\"o\">/</span><span class=\"n\">django</span><span class=\"o\">.</span><span class=\"n\">git</span>\n</code></pre></div>\n</section>\n<section id=\"working-on-a-ticket\">\n<h2>在工单上工作<a class=\"heading-anchor\" href=\"#working-on-a-ticket\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>When working on a ticket, create a new branch for the work, and base that work\non upstream/master:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">git</span> <span class=\"n\">checkout</span> <span class=\"o\">-</span><span class=\"n\">b</span> <span class=\"n\">ticket_xxxxx</span> <span class=\"n\">upstream</span><span class=\"o\">/</span><span class=\"n\">master</span>\n</code></pre></div>\n<p>-b 参数在本地为您创建一个新分支。 即使是最小的事情，也不要犹豫创建新分支——这就是它们的用途。</p>\n<p>相反，如果您正在1.4分支上进行修复，则可以执行以下操作：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">git</span> <span class=\"n\">checkout</span> <span class=\"o\">-</span><span class=\"n\">b</span> <span class=\"n\">ticket_xxxxx_1_4</span> <span class=\"n\">upstream</span><span class=\"o\">/</span><span class=\"n\">stable</span><span class=\"o\">/</span><span class=\"mf\">1.4</span><span class=\"o\">.</span><span class=\"n\">x</span>\n</code></pre></div>\n<p>Assume the work is carried on the ticket_xxxxx branch. Make some changes and\ncommit them:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">git</span> <span class=\"n\">commit</span>\n</code></pre></div>\n<p>编写提交消息时，请遵循提交 <a class=\"reference internal\" href=\"/zh-hans/3.1/internals/contributing/committing-code/#committing-guidelines\"><span class=\"std std-ref\">commit message guidelines</span></a> 以简化提交者的工作。 如果您不习惯使用英语，请尝试至少准确描述提交的功能。</p>\n<p>如果您需要在分支上执行其他工作，请根据需要多次提交：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">git</span> <span class=\"n\">commit</span> <span class=\"o\">-</span><span class=\"n\">m</span> <span class=\"s1\">&#39;Added two more tests for edge cases&#39;</span>\n</code></pre></div>\n<section id=\"publishing-work\">\n<h3>发布工作成果<a class=\"heading-anchor\" href=\"#publishing-work\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>You can publish your work on GitHub by running:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">git</span> <span class=\"n\">push</span> <span class=\"n\">origin</span> <span class=\"n\">ticket_xxxxx</span>\n</code></pre></div>\n<p>When you go to your GitHub page, you will notice a new branch has been created.</p>\n<p>If you are working on a Trac ticket, you should mention in the ticket that\nyour work is available from branch ticket_xxxxx of your GitHub repo. Include a\nlink to your branch.</p>\n<p>请注意，在Git中，上述分支称为“主题分支”。 您可以自由地重写该分支的历史记录，例如，使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">git</span> <span class=\"pre\">rebase</span></code> 变更基本。 其他人不应在这样的分支上进行工作，因为当您编辑提交时，他们的副本会损坏。</p>\n<p>There are also &quot;public branches&quot;. These are branches other people are supposed\nto fork, so the history of these branches should never change. Good examples\nof public branches are the <code class=\"docutils literal notranslate\"><span class=\"pre\">master</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">stable/A.B.x</span></code> branches in the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">django/django</span></code> repository.</p>\n<p>当您准备将工作成果并入Django时，应在GitHub上创建一个pull请求。好的拉取请求要求：</p>\n<ul class=\"simple\">\n<li><p>按照:doc:coding style &lt;coding-style&gt; ，每个提交都进行一次逻辑更改，</p></li>\n<li><p>每次提交的格式正确的消息：摘要行，其后以72个字符包装的段落——有关详细信息，请参见 <a class=\"reference internal\" href=\"/zh-hans/3.1/internals/contributing/committing-code/#committing-guidelines\"><span class=\"std std-ref\">committing guidelines</span></a> 。</p></li>\n<li><p>如果需要，带有文档和测试——实际上一直需要测试，除了文档更改外。</p></li>\n</ul>\n<p>测试套件必须通过，并且文档的构建必须没有警告。</p>\n<p>Once you have created your pull request, you should add a comment in the\nrelated Trac ticket explaining what you've done. In particular, you should note\nthe environment in which you ran the tests, for instance: &quot;all tests pass\nunder SQLite and MySQL&quot;.</p>\n<p>Pull requests at GitHub have only two states: open and closed. The committer\nwho will deal with your pull request has only two options: merge it or close\nit. For this reason, it isn't useful to make a pull request until the code is\nready for merging -- or sufficiently close that a committer will finish it\nthemselves.</p>\n</section>\n<section id=\"rebasing-branches\">\n<h3>分支变基<a class=\"heading-anchor\" href=\"#rebasing-branches\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>In the example above, you created two commits, the &quot;Fixed ticket_xxxxx&quot; commit\nand &quot;Added two more tests&quot; commit.</p>\n<p>我们不想在您的代码库中拥有您工作过程的全部历史记录。您的提交“添加了两个以上的测试”将毫无助益。相反，我们只希望一次提交包含您的所有工作。</p>\n<p>要重做分支的历史记录，可以使用交互式rebase将提交压缩为一个：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">git</span> <span class=\"n\">rebase</span> <span class=\"o\">-</span><span class=\"n\">i</span> <span class=\"n\">HEAD</span><span class=\"o\">~</span><span class=\"mi\">2</span>\n</code></pre></div>\n<p>上面的 HEAD~2 是最近两次提交的简写。 上面的命令将打开一个编辑器，显示两个提交，前缀为 &quot;pick&quot; 。</p>\n<p>Change &quot;pick&quot; on the second line to &quot;squash&quot; instead. This will keep the\nfirst commit, and squash the second commit into the first one. Save and quit\nthe editor. A second editor window should open, so you can reword the\ncommit message for the commit now that it includes both your steps.</p>\n<p>您还可以在rebase中使用“编辑”选项。这样，您可以更改单个提交，例如修复文档字符串中的错字：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">git</span> <span class=\"n\">rebase</span> <span class=\"o\">-</span><span class=\"n\">i</span> <span class=\"n\">HEAD</span><span class=\"o\">~</span><span class=\"mi\">3</span>\n<span class=\"c1\"># Choose edit, pick, pick for the commits</span>\n<span class=\"c1\"># Now you are able to rework the commit (use git add normally to add changes)</span>\n<span class=\"c1\"># When finished, commit work with &quot;--amend&quot; and continue</span>\n<span class=\"n\">git</span> <span class=\"n\">commit</span> <span class=\"o\">--</span><span class=\"n\">amend</span>\n<span class=\"c1\"># Reword the commit message if needed</span>\n<span class=\"n\">git</span> <span class=\"n\">rebase</span> <span class=\"o\">--</span><span class=\"k\">continue</span>\n<span class=\"c1\"># The second and third commits should be applied.</span>\n</code></pre></div>\n<p>If your topic branch is already published at GitHub, for example if you're\nmaking minor changes to take into account a review, you will need to force-push\nthe changes:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">git</span> <span class=\"n\">push</span> <span class=\"o\">-</span><span class=\"n\">f</span> <span class=\"n\">origin</span> <span class=\"n\">ticket_xxxxx</span>\n</code></pre></div>\n<p>Note that this will rewrite history of ticket_xxxxx - if you check the commit\nhashes before and after the operation at GitHub you will notice that the commit\nhashes do not match anymore. This is acceptable, as the branch is a topic\nbranch, and nobody should be basing their work on it.</p>\n</section>\n<section id=\"after-upstream-has-changed\">\n<h3>在上游发生变化之后<a class=\"heading-anchor\" href=\"#after-upstream-has-changed\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>When upstream (<code class=\"docutils literal notranslate\"><span class=\"pre\">django/django</span></code>) has changed, you should rebase your work. To\ndo this, use:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">git</span> <span class=\"n\">fetch</span> <span class=\"n\">upstream</span>\n<span class=\"n\">git</span> <span class=\"n\">rebase</span>\n</code></pre></div>\n<p>The work is automatically rebased using the branch you forked on, in the\nexample case using <code class=\"docutils literal notranslate\"><span class=\"pre\">upstream/master</span></code>.</p>\n<p>rebase命令暂时删除所有本地提交，应用上游提交，然后在工作上再次应用本地提交。</p>\n<p>If there are merge conflicts, you will need to resolve them and then use <code class=\"docutils literal notranslate\"><span class=\"pre\">git</span>\n<span class=\"pre\">rebase</span> <span class=\"pre\">--continue</span></code>. At any point you can use <code class=\"docutils literal notranslate\"><span class=\"pre\">git</span> <span class=\"pre\">rebase</span> <span class=\"pre\">--abort</span></code> to return\nto the original state.</p>\n<p>请注意，您想在上游 <em>变基</em> ，而不是 <em>合并</em> 上游。</p>\n<p>这样做的原因是，通过重新定基，您的提交将始终在上游工作的*基础*上，而不是与上游所做的更改*混合在一起*。这样，您的分支将只包含与其主题相关的提交，这使得压缩更加容易。</p>\n</section>\n<section id=\"after-review\">\n<h3>审阅之后<a class=\"heading-anchor\" href=\"#after-review\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>在审核者未要求更改的情况下，将任何不重要的代码放入内核是很不正常的。 在这种情况下，通常最好将更改添加为对工作的一次增量提交。 这使审阅者可以轻松地检查您所做的更改。</p>\n<p>在这种情况下，请执行审阅者要求的更改。 尽可能频繁地提交。 在发布更改之前，请重新设定工作基础。 如果添加了两个提交，则将运行：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">git</span> <span class=\"n\">rebase</span> <span class=\"o\">-</span><span class=\"n\">i</span> <span class=\"n\">HEAD</span><span class=\"o\">~</span><span class=\"mi\">2</span>\n</code></pre></div>\n<p>将第二个提交压缩为第一个。 按照以下内容编写提交消息：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">Made</span> <span class=\"n\">changes</span> <span class=\"n\">asked</span> <span class=\"ow\">in</span> <span class=\"n\">review</span> <span class=\"n\">by</span> <span class=\"o\">&lt;</span><span class=\"n\">reviewer</span><span class=\"o\">&gt;</span>\n\n<span class=\"o\">-</span> <span class=\"n\">Fixed</span> <span class=\"n\">whitespace</span> <span class=\"n\">errors</span> <span class=\"ow\">in</span> <span class=\"n\">foobar</span>\n<span class=\"o\">-</span> <span class=\"n\">Reworded</span> <span class=\"n\">the</span> <span class=\"n\">docstring</span> <span class=\"n\">of</span> <span class=\"n\">bar</span><span class=\"p\">()</span>\n</code></pre></div>\n<p>Finally, push your work back to your GitHub repository. Since you didn't touch\nthe public commits during the rebase, you should not need to force-push:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">git</span> <span class=\"n\">push</span> <span class=\"n\">origin</span> <span class=\"n\">ticket_xxxxx</span>\n</code></pre></div>\n<p>您的拉取请求现在也应该包含新的提交。</p>\n<p>请注意，提交者在提交代码时可能会将审阅提交压缩为先前的提交。</p>\n</section>\n</section>\n<section id=\"working-on-a-patch\">\n<h2>Working on a patch<a class=\"heading-anchor\" href=\"#working-on-a-patch\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>One of the ways that developers can contribute to Django is by reviewing\npatches. Those patches will typically exist as pull requests on GitHub and\ncan be easily integrated into your local repository:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">git</span> <span class=\"n\">checkout</span> <span class=\"o\">-</span><span class=\"n\">b</span> <span class=\"n\">pull_xxxxx</span> <span class=\"n\">upstream</span><span class=\"o\">/</span><span class=\"n\">master</span>\n<span class=\"n\">curl</span> <span class=\"n\">https</span><span class=\"p\">:</span><span class=\"o\">//</span><span class=\"n\">github</span><span class=\"o\">.</span><span class=\"n\">com</span><span class=\"o\">/</span><span class=\"n\">django</span><span class=\"o\">/</span><span class=\"n\">django</span><span class=\"o\">/</span><span class=\"n\">pull</span><span class=\"o\">/</span><span class=\"n\">xxxxx</span><span class=\"o\">.</span><span class=\"n\">patch</span> <span class=\"o\">|</span> <span class=\"n\">git</span> <span class=\"n\">am</span>\n</code></pre></div>\n<p>This will create a new branch and then apply the changes from the pull request\nto it. At this point you can run the tests or do anything else you need to\ndo to investigate the quality of the patch.</p>\n<p>For more detail on working with pull requests see the\n<a class=\"reference internal\" href=\"/zh-hans/3.1/internals/contributing/committing-code/#handling-pull-requests\"><span class=\"std std-ref\">guidelines for committers</span></a>.</p>\n</section>\n<section id=\"summary\">\n<h2>概览<a class=\"heading-anchor\" href=\"#summary\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<ul class=\"simple\">\n<li><p>如果可以，请在GitHub上工作。</p></li>\n<li><p>通过链接到您的GitHub分支来宣布您在Trac工单上的工作。</p></li>\n<li><p>准备就绪后，请提出拉取请求。</p></li>\n<li><p>使您的拉取请求尽可能地好。</p></li>\n<li><p>在对您的工作进行修复时，请使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">git</span> <span class=\"pre\">rebase</span> <span class=\"pre\">-i</span></code> 压缩提交。</p></li>\n<li><p>当上游发生变化时，请执行 <code class=\"docutils literal notranslate\"><span class=\"pre\">git</span> <span class=\"pre\">fetch</span> <span class=\"pre\">upstream;</span> <span class=\"pre\">git</span> <span class=\"pre\">rebase</span></code>。</p></li>\n</ul>\n</section>","rootId":"working-with-git-and-github","toc":[{"title":"安装 Git","anchor":"installing-git","children":[]},{"title":"设置本地仓库","anchor":"setting-up-local-repository","children":[]},{"title":"在工单上工作","anchor":"working-on-a-ticket","children":[{"title":"发布工作成果","anchor":"publishing-work","children":[]},{"title":"分支变基","anchor":"rebasing-branches","children":[]},{"title":"在上游发生变化之后","anchor":"after-upstream-has-changed","children":[]},{"title":"审阅之后","anchor":"after-review","children":[]}]},{"title":"Working on a patch","anchor":"working-on-a-patch","children":[]},{"title":"概览","anchor":"summary","children":[]}],"breadcrumbs":[{"docname":"internals/index","title":"Django internals","url":"/zh-hans/3.1/internals/"},{"docname":"internals/contributing/index","title":"为 Django 做贡献","url":"/zh-hans/3.1/internals/contributing/"},{"docname":"internals/contributing/writing-code/index","title":"编写代码","url":"/zh-hans/3.1/internals/contributing/writing-code/"}],"prev":{"docname":"internals/contributing/writing-code/submitting-patches","title":"提交补丁","url":"/zh-hans/3.1/internals/contributing/writing-code/submitting-patches/"},"next":{"docname":"internals/contributing/writing-code/javascript","title":"JavaScript","url":"/zh-hans/3.1/internals/contributing/writing-code/javascript/"},"formats":{"html":"/zh-hans/3.1/internals/contributing/writing-code/working-with-git/","markdown":"/zh-hans/3.1/internals/contributing/writing-code/working-with-git.md","json":"/zh-hans/3.1/internals/contributing/writing-code/working-with-git.json"},"source":"https://github.com/django/django/blob/stable/3.1.x/docs/internals/contributing/writing-code/working-with-git.txt","official":"https://docs.djangoproject.com/zh-hans/3.1/internals/contributing/writing-code/working-with-git/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0"],"inLocales":["en","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}