{"title":"Enviando código","version":"6.0","locale":"pt-br","docname":"internals/contributing/committing-code","url":"/pt-br/6.0/internals/contributing/committing-code/","canonical":"https://djangodocs.dev/pt-br/6.0/internals/contributing/committing-code/","summary":"This section is addressed to the mergers and to anyone interested in knowing how code gets committed into Django. The Regras de commit apply to all contributors,…","html":"<h1>Enviando código<a class=\"heading-anchor\" href=\"#committing-code\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>This section is addressed to the mergers and to anyone interested in knowing\nhow code gets committed into Django. The <a class=\"reference internal\" href=\"#committing-guidelines\"><span class=\"std std-ref\">Regras de commit</span></a> apply\nto all contributors, with or without commit rights.</p>\n<p>If you’re a community member who wants to contribute code to Django, look at\n<a class=\"reference internal\" href=\"/pt-br/6.0/internals/contributing/writing-code/working-with-git/\"><span class=\"doc\">Trabalhando com Git e GitHub</span></a> instead.</p>\n<section id=\"handling-pull-requests\">\n<span id=\"id1\"></span><h2>Manipulando pull requests<a class=\"heading-anchor\" href=\"#handling-pull-requests\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Como o Django é hospeado no GitbHub, os patches são provisionados na forma de pull requests.</p>\n<p>When committing a pull request, make sure each individual commit matches the\ncommit guidelines described below. Contributors are expected to provide the\nbest pull requests possible. In practice mergers - who will likely be more\nfamiliar with the commit guidelines - may decide to bring a commit up to\nstandard themselves.</p>\n<p>You may want to have Jenkins or GitHub actions test the pull request with one\nof the pull request builders that doesn’t run automatically, such as Oracle or\nSelenium. See the <a class=\"reference external\" href=\"https://code.djangoproject.com/wiki/CI\">CI wiki page</a> for instructions.</p>\n<p>If you find yourself checking out pull requests locally more often, this git\nalias will be helpful:</p>\n<div class=\"code-block\" data-language=\"ini\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Ini</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=\"Ini code\"><code><span class=\"k\">[alias]</span>\n<span class=\"w\">    </span><span class=\"na\">pr</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"s\">!sh -c \\&quot;git fetch upstream pull/${1}/head:pr/${1} &amp;&amp; git checkout pr/${1}\\&quot;</span>\n</code></pre></div>\n<p>Add it to your <code class=\"docutils literal notranslate\"><span class=\"pre\">~/.gitconfig</span></code>, and set <code class=\"docutils literal notranslate\"><span class=\"pre\">upstream</span></code> to be <code class=\"docutils literal notranslate\"><span class=\"pre\">django/django</span></code>.\nThen you can run <code class=\"docutils literal notranslate\"><span class=\"pre\">git</span> <span class=\"pre\">pr</span> <span class=\"pre\">####</span></code> to checkout the corresponding pull request.</p>\n<p>A partir deste momento, você pode trabalhar no código. Utilize <code class=\"docutils literal notranslate\"><span class=\"pre\">git</span> <span class=\"pre\">rebase</span> <span class=\"pre\">-i</span></code> e <code class=\"docutils literal notranslate\"><span class=\"pre\">git</span> <span class=\"pre\">commit</span> <span class=\"pre\">--amend</span></code> para garantir que os commits tenham o nível de qualidade desejado. Quando você estiver pronto:</p>\n<div class=\"console\" data-console><div class=\"console-panel\" data-platform=\"unix\"><p class=\"console-label\" id=\"console-0-unix-label\">Linux / macOS</p><div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</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=\"Shell code\"><code><span class=\"gp\">$ </span><span class=\"c1\"># Pull in the latest changes from main.</span>\n<span class=\"gp\">$ </span>git<span class=\"w\"> </span>checkout<span class=\"w\"> </span>main\n<span class=\"gp\">$ </span>git<span class=\"w\"> </span>pull<span class=\"w\"> </span>upstream<span class=\"w\"> </span>main\n<span class=\"gp\">$ </span><span class=\"c1\"># Rebase the pull request on main.</span>\n<span class=\"gp\">$ </span>git<span class=\"w\"> </span>checkout<span class=\"w\"> </span>pr/####\n<span class=\"gp\">$ </span>git<span class=\"w\"> </span>rebase<span class=\"w\"> </span>main\n<span class=\"gp\">$ </span>git<span class=\"w\"> </span>checkout<span class=\"w\"> </span>main\n<span class=\"gp\">$ </span><span class=\"c1\"># Merge the work as &quot;fast-forward&quot; to main to avoid a merge commit.</span>\n<span class=\"gp\">$ </span><span class=\"c1\"># (in practice, you can omit &quot;--ff-only&quot; since you just rebased)</span>\n<span class=\"gp\">$ </span>git<span class=\"w\"> </span>merge<span class=\"w\"> </span>--ff-only<span class=\"w\"> </span>pr/XXXX\n<span class=\"gp\">$ </span><span class=\"c1\"># If you&#39;re not sure if you did things correctly, check that only the</span>\n<span class=\"gp\">$ </span><span class=\"c1\"># changes you expect will be pushed to upstream.</span>\n<span class=\"gp\">$ </span>git<span class=\"w\"> </span>push<span class=\"w\"> </span>--dry-run<span class=\"w\"> </span>upstream<span class=\"w\"> </span>main\n<span class=\"gp\">$ </span><span class=\"c1\"># Push!</span>\n<span class=\"gp\">$ </span>git<span class=\"w\"> </span>push<span class=\"w\"> </span>upstream<span class=\"w\"> </span>main\n<span class=\"gp\">$ </span><span class=\"c1\"># Delete the pull request branch.</span>\n<span class=\"gp\">$ </span>git<span class=\"w\"> </span>branch<span class=\"w\"> </span>-d<span class=\"w\"> </span>pr/xxxx\n</code></pre></div>\n</div><div class=\"console-panel\" data-platform=\"windows\"><p class=\"console-label\" id=\"console-0-windows-label\">Windows</p><div class=\"code-block\" data-language=\"doscon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Windows</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=\"Windows shell\"><code><span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM Pull in the latest changes from main.</span>\n<span class=\"gp\">...\\&gt;</span> git checkout main\n<span class=\"gp\">...\\&gt;</span> git pull upstream main\n<span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM Rebase the pull request on main.</span>\n<span class=\"gp\">...\\&gt;</span> git checkout pr/####\n<span class=\"gp\">...\\&gt;</span> git rebase main\n<span class=\"gp\">...\\&gt;</span> git checkout main\n<span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM Merge the work as &quot;fast-forward&quot; to main to avoid a merge commit.</span>\n<span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM (in practice, you can omit &quot;--ff-only&quot; since you just rebased)</span>\n<span class=\"gp\">...\\&gt;</span> git merge --ff-only pr/XXXX\n<span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM If you&#39;re not sure if you did things correctly, check that only the</span>\n<span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM changes you expect will be pushed to upstream.</span>\n<span class=\"gp\">...\\&gt;</span> git push --dry-run upstream main\n<span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM Push!</span>\n<span class=\"gp\">...\\&gt;</span> git push upstream main\n<span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM Delete the pull request branch.</span>\n<span class=\"gp\">...\\&gt;</span> git branch -d pr/xxxx\n</code></pre></div></div></div>\n<p>Force push to the branch after rebasing on main but before merging and pushing\nto upstream. This allows the commit hashes on main and the branch to match\nwhich automatically closes the pull request.</p>\n<p>If a pull request doesn’t need to be merged as multiple commits, you can use\nGitHub’s “Squash and merge” button on the website. Edit the commit message as\nneeded to conform to <a class=\"reference internal\" href=\"#committing-guidelines\"><span class=\"std std-ref\">the guidelines</span></a> and remove\nthe pull request number that’s automatically appended to the message’s first\nline.</p>\n<p>Quando estiver reescrevendo o histórico de commits de um pull request, o objetivo é fazer com que o histórico de commits do Django seja o mais útil possível:</p>\n<ul class=\"simple\">\n<li><p>Se um patch possui retornos e avanços nos commits, então reescreva esses em um só. Por exemplo, se um commit adiciona mais código e um segundo commit faz ajustes em problemas de estilo introduzidos pelo primeiro commit, esses commits devem ser unificados antes de se fazer um merge.</p></li>\n<li><p>Separe as mudanças em diferentes commits por grupos lógicos: se você faz uma limpeza de estilo ao mesmo tempo em que você faz outras mudanças em um arquivo, a separação dessas mudanças em dois commits diferentes fará a revisão do histórico de alterações mais simples.</p></li>\n<li><p>Cuidado com merges de branches do upstream dentro de pull requests.</p></li>\n<li><p>Testes devem passar e a documentação deve ser gerada depois de cada commit. Nem os testes, nem a documentação devem emitir avisos.</p></li>\n<li><p>Patchs triviais e pequenos costumam ser melhor realizados em um único commit. Trabalhos médios ou maiores podem ser quebrados em múltiplos commits se isso fizer sentido.</p></li>\n</ul>\n<p>Practicality beats purity, so it is up to each merger to decide how much\nhistory mangling to do for a pull request. The main points are engaging the\ncommunity, getting work done, and having a usable commit history.</p>\n</section>\n<section id=\"committing-guidelines\">\n<span id=\"id2\"></span><h2>Regras de commit<a class=\"heading-anchor\" href=\"#committing-guidelines\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>These guidelines apply to all commits to Django’s Git repository, whether\nsubmitted by a contributor via a pull request or landed directly by a merger:</p>\n<ul>\n<li><p>Nunca altere o histórico publicado dos “branches” do  <code class=\"docutils literal notranslate\"><span class=\"pre\">django/django</span></code> através de um “push” forçado. Se for absolutamente necessário (por razões de segurança), primeiro discuta a situação com o time.</p></li>\n<li><p>For any medium-to-big changes, where “medium-to-big” is according to\nyour judgment, please bring things up on the <a class=\"reference external\" href=\"https://forum.djangoproject.com/\">Django Forum</a> before making\nthe change.</p>\n<p>If you bring something up and nobody responds, please don’t take that\nto mean your idea is great and should be implemented immediately because\nnobody contested it. Everyone doesn’t always have a lot of time to read\ndiscussions immediately, so you may have to wait a couple of days before\ngetting a response.</p>\n</li>\n<li><p>Write detailed commit messages in the past tense, not present tense, and\nend the subject line with a period.</p>\n<ul class=\"simple\">\n<li><p>Correct: “Fixed Unicode bug in RSS API.”</p></li>\n<li><p>Incorrect: “Fixes Unicode bug in RSS API.” (present tense)</p></li>\n<li><p>Incorrect: “Fixing Unicode bug in RSS API.” (“-ing” form)</p></li>\n<li><p>Incorrect: “Fixed Unicode bug in RSS API” (missing trailing period)</p></li>\n</ul>\n<p>The commit message should be in lines of 72 chars maximum. There should be\na subject line, separated by a blank line and then paragraphs of 72 char\nlines. The limits are soft. For the subject line, shorter is better.</p>\n<p>In the body of the commit message more detail is better than less, and should\nexplain <em>why</em> the change was made, not <em>what</em> was changed or <em>how</em>. The code\nitself shows what changed; the commit message should provide the context and\nreasoning that the code cannot.</p>\n<p>Credit the contributors in the commit message: “Thanks A for the report and B\nfor review.” Use git’s <a class=\"reference external\" href=\"https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors\">Co-Authored-By</a> as appropriate, including anyone\nwhose earlier work the change builds on.</p>\n<p>Por exemplo:</p>\n<div class=\"code-block\" data-language=\"none\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">None</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=\"None code\"><code>Fixed #18307 -- Added git workflow guidelines.\n\nRefactored the Django&#39;s documentation to remove mentions of SVN\nspecific tasks. Added guidelines of how to use Git, GitHub, and\nhow to use pull request together with Trac instead.\n\nThanks to Full Name for the report, and to Reviewer for reviews.\n</code></pre></div>\n</li>\n<li><p>Para commits em uma branch, coloque antes da mensagem de commit o nome da branch. Por exemplo: “[1.4.x] Fixed #xxxxx – Adicionado suporte para leitura de mentes.”</p></li>\n<li><p>Limit commits to the most granular change that makes sense. This means,\nuse frequent small commits rather than infrequent large commits. For\nexample, if implementing feature X requires a small change to library Y,\nfirst commit the change to library Y, then commit feature X in a separate\ncommit. This goes a <em>long way</em> in helping everyone follow your changes.</p></li>\n<li><p>Separate bug fixes from feature changes. Bugfixes may need to be backported\nto the stable branch, according to <a class=\"reference internal\" href=\"/pt-br/6.0/internals/release-process/#supported-versions-policy\"><span class=\"std std-ref\">Versões suportadas</span></a>.</p></li>\n<li><p>Se o seu commit fecha um ticket no rastreador de tickets do Django, comece a sua mensagem de commit com o texto “Fixed #xxxxx”, onde “xxxxx” é o número do ticket que o seu commit corrige. Exemplo: “Corrigido #123 – Adicionada a funcionalidade whizbang.”.\nNós configuramos o Trac de modo que qualquer mensagem de commit nesse formato irá automaticamente fechar o ticket referenciado e colocar um comentário nele com a mensagem completa do commit.</p>\n<p>Para os curiosos, nós estamos utilizando um <a class=\"reference external\" href=\"https://github.com/trac-hacks/trac-github\">Trac plugin</a> para isso.</p>\n</li>\n</ul>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Nota</p>\n<p>Note that the Trac integration doesn’t know anything about pull requests.\nSo if you try to close a pull request with the phrase “closes #400” in your\ncommit message, GitHub will close the pull request, but the Trac plugin\nwill not close the same numbered ticket in Trac.</p>\n</aside>\n<ul>\n<li><p>Se o seu commit faz referência a um ticket no rastreador de tickets do Django mas <em>não</em> fecha o ticket, inclua a frase  “Refs #xxxxx”, onde “xxxxx” é o número do ticket que o seu commit faz menção. Isso irá automaticamente postar um comentário na página do respectivo ticket.</p></li>\n<li><p>Escreva mensagens de commit para backports usando esse formato:</p>\n<div class=\"code-block\" data-language=\"none\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">None</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=\"None code\"><code>[&lt;Django version&gt;] Fixed &lt;ticket&gt; -- &lt;description&gt;\n\nBackport of &lt;revision&gt; from &lt;branch&gt;.\n</code></pre></div>\n<p>Por exemplo:</p>\n<div class=\"code-block\" data-language=\"none\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">None</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=\"None code\"><code>[1.3.x] Fixed #17028 -- Changed diveintopython.org -&gt; diveintopython.net.\n\nBackport of 80c0cbf1c97047daed2c5b41b296bbc56fe1d7e3 from main.\n</code></pre></div>\n<p>There’s a <a class=\"reference external\" href=\"https://code.djangoproject.com/wiki/MergerTips#AutomatingBackports\">script on the wiki</a> to\nautomate this.</p>\n<p>If the commit fixes a regression, include this in the commit message:</p>\n<div class=\"code-block\" data-language=\"none\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">None</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=\"None code\"><code>Regression in 6ecccad711b52f9273b1acb07a57d3f806e93928.\n</code></pre></div>\n<p>(use the commit hash where the regression was introduced).</p>\n</li>\n</ul>\n</section>\n<section id=\"reverting-commits\">\n<h2>Revertendo commits<a class=\"heading-anchor\" href=\"#reverting-commits\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Ninguém é perfeito; erros serão comitados.</p>\n<p>But try very hard to ensure that mistakes don’t happen. Just because we have a\nreversion policy doesn’t relax your responsibility to aim for the highest\nquality possible. Really: double-check your work, or have it checked by\nanother merger <strong>before</strong> you commit it in the first place!</p>\n<p>Quando um commit indevido é descoberto, por favor siga as instruções abaixo:</p>\n<ul class=\"simple\">\n<li><p>Se possível, deixe que o autor original reverta o seu próprio commit.</p></li>\n<li><p>Não faça o revert das mudanças de outro autor sem a permissão do autor original.</p></li>\n<li><p>Utilize o git revert – isso irá fazer um commit reverso, mas o commit original ainda será parte do histórico de commits.</p></li>\n<li><p>If the original author can’t be reached (within a reasonable amount\nof time – a day or so) and the problem is severe – crashing bug,\nmajor test failures, etc. – then ask for objections on the <a class=\"reference external\" href=\"https://forum.djangoproject.com/\">Django Forum</a>\nthen revert if there are none.</p></li>\n<li><p>Se o problema é pequeno (uma funcionalidade congelada, por exemplo) aguarde.</p></li>\n<li><p>If there’s a disagreement between the merger and the reverter-to-be then try\nto work it out on the <a class=\"reference external\" href=\"https://forum.djangoproject.com/\">Django Forum</a> . If an agreement can’t be reached then\nit should be put to a vote.</p></li>\n<li><p>Se o commit introduziu uma vulnerabilidade de segurança confirmada, aberta então o commit deve ser revertido imediatamente sem permissão de ninguém.</p></li>\n<li><p>O mantenedor da branch de releases pode voltar commits nessa branch sem permissão caso o commit tenha quebrado a branch de releases.</p></li>\n<li><p>If you mistakenly push a topic branch to <code class=\"docutils literal notranslate\"><span class=\"pre\">django/django</span></code>, delete it.\nFor instance, if you did: <code class=\"docutils literal notranslate\"><span class=\"pre\">git</span> <span class=\"pre\">push</span> <span class=\"pre\">upstream</span> <span class=\"pre\">feature_antigravity</span></code>,\ndo a reverse push: <code class=\"docutils literal notranslate\"><span class=\"pre\">git</span> <span class=\"pre\">push</span> <span class=\"pre\">upstream</span> <span class=\"pre\">:feature_antigravity</span></code>.</p></li>\n</ul>\n</section>","rootId":"committing-code","toc":[{"title":"Manipulando pull requests","anchor":"handling-pull-requests","children":[]},{"title":"Regras de commit","anchor":"committing-guidelines","children":[]},{"title":"Revertendo commits","anchor":"reverting-commits","children":[]}],"breadcrumbs":[{"docname":"internals/index","title":"Funcionamento interno do Projeto Django","url":"/pt-br/6.0/internals/"},{"docname":"internals/contributing/index","title":"Contribuindo com o Django","url":"/pt-br/6.0/internals/contributing/"},{"docname":"internals/contributing/writing-code/index","title":"Contributing code","url":"/pt-br/6.0/internals/contributing/writing-code/"}],"prev":{"docname":"internals/contributing/accessibility","title":"Accessibility","url":"/pt-br/6.0/internals/contributing/accessibility/"},"next":{"docname":"internals/contributing/writing-documentation","title":"Escrevendo a documentação","url":"/pt-br/6.0/internals/contributing/writing-documentation/"},"formats":{"html":"/pt-br/6.0/internals/contributing/committing-code/","markdown":"/pt-br/6.0/internals/contributing/committing-code.md","json":"/pt-br/6.0/internals/contributing/committing-code.json"},"source":"https://github.com/django/django/blob/stable/6.0.x/docs/internals/contributing/committing-code.txt","official":"https://docs.djangoproject.com/pt-br/6.0/internals/contributing/committing-code/","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","1.11","1.10","1.9"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}