{"title":"Commit de code","version":"2.1","locale":"fr","docname":"internals/contributing/committing-code","url":"/fr/2.1/internals/contributing/committing-code/","canonical":"https://djangodocs.dev/fr/2.1/internals/contributing/committing-code/","summary":"Cette section s’adresse aux commiteurs et à quiconque est intéressé à savoir comment le code est commité dans Django.","html":"<h1>Commit de code<a class=\"heading-anchor\" href=\"#committing-code\"><span class=\"visually-hidden\">Lien vers cette rubrique</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>Cette section s’adresse aux commiteurs et à quiconque est intéressé à savoir comment le code est commité dans Django. Si vous êtes un membre de la communauté désirant contribuer du code à Django, consultez plutôt <a class=\"reference internal\" href=\"/fr/2.1/internals/contributing/writing-code/working-with-git/\"><span class=\"doc\">Travailler avec Git et GitHub</span></a>.</p>\n<section id=\"handling-pull-requests\">\n<span id=\"id1\"></span><h2>Gestion des requêtes de contribution<a class=\"heading-anchor\" href=\"#handling-pull-requests\"><span class=\"visually-hidden\">Lien vers cette rubrique</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Comme Django est hébergé sur GitHub, la plupart des correctifs sont fournis sous la forme de requêtes de contribution (« pull request »).</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 however, committers - who will likely\nbe more familiar with the commit guidelines - may decide to bring a commit up\nto standard themselves.</p>\n<p>Il peut être souhaitable de demander à Jenkins de tester la requête de contribution à l’aide d’un des constructeurs qui ne se lance pas automatiquement, tel que Oracle ou Selenium. Voir la <a class=\"reference external\" href=\"https://code.djangoproject.com/wiki/Jenkins\">page de Wiki de Jenkins</a> pour plus d’instructions.</p>\n<p>Une façon simple de récupérer localement une requête de contribution est d’ajouter un alias à votre fichier <code class=\"docutils literal notranslate\">~/.gitconfig</code> (en supposant que <code class=\"docutils literal notranslate\">upstream</code> correspond à <code class=\"docutils literal notranslate\">django/django</code>) :</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>[alias]\n    pr = !sh -c \\&quot;git fetch upstream pull/${1}/head:pr/${1} &amp;&amp; git checkout pr/${1}\\&quot;\n</code></pre></div>\n<p>Vous pouvez maintenant simplement exécuter <code class=\"docutils literal notranslate\">git pr ####</code> pour récupérer en local la requête de contribution correspondante.</p>\n<p>À ce stade, vous pouvez travailler sur le code. Utilisez <code class=\"docutils literal notranslate\">git rebase -i</code> et <code class=\"docutils literal notranslate\">git commit --amend</code> pour vous assurer que les commits présentent le niveau de qualité requis. Quand vous êtes prêt :</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 master.</span>\n<span class=\"gp\">$ </span>git checkout master\n<span class=\"gp\">$ </span>git pull upstream master\n<span class=\"gp\">$ </span><span class=\"c1\"># Rebase the pull request on master.</span>\n<span class=\"gp\">$ </span>git checkout pr/####\n<span class=\"gp\">$ </span>git rebase master\n<span class=\"gp\">$ </span>git checkout master\n<span class=\"gp\">$ </span><span class=\"c1\"># Merge the work as &quot;fast-forward&quot; to master 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 merge --ff-only 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 push --dry-run upstream master\n<span class=\"gp\">$ </span><span class=\"c1\"># Push!</span>\n<span class=\"gp\">$ </span>git push upstream master\n<span class=\"gp\">$ </span><span class=\"c1\"># Delete the pull request branch.</span>\n<span class=\"gp\">$ </span>git branch -d 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 master.</span>\n<span class=\"gp\">...\\&gt;</span> git checkout master\n<span class=\"gp\">...\\&gt;</span> git pull upstream master\n<span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM Rebase the pull request on master.</span>\n<span class=\"gp\">...\\&gt;</span> git checkout pr/####\n<span class=\"gp\">...\\&gt;</span> git rebase master\n<span class=\"gp\">...\\&gt;</span> git checkout master\n<span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM Merge the work as &quot;fast-forward&quot; to master 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 master\n<span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM Push!</span>\n<span class=\"gp\">...\\&gt;</span> git push upstream master\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 master but before merging and\npushing to upstream. This allows the commit hashes on master and the branch to\nmatch which 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>When rewriting the commit history of a pull request, the goal is to make\nDjango’s commit history as usable as possible:</p>\n<ul class=\"simple\">\n<li><p>If a patch contains back-and-forth commits, then rewrite those into one.\nFor example, if a commit adds some code and a second commit fixes stylistic\nissues introduced in the first commit, those commits should be squashed\nbefore merging.</p></li>\n<li><p>Separate changes to different commits by logical grouping: if you do a\nstylistic cleanup at the same time as you do other changes to a file,\nseparating the changes into two different commits will make reviewing\nhistory easier.</p></li>\n<li><p>Beware of merges of upstream branches in the pull requests.</p></li>\n<li><p>Tests should pass and docs should build after each commit. Neither the\ntests nor the docs should emit warnings.</p></li>\n<li><p>Trivial and small patches usually are best done in one commit. Medium to\nlarge work may be split into multiple commits if it makes sense.</p></li>\n</ul>\n<p>Practicality beats purity, so it is up to each committer 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>Lignes directrices pour les commits<a class=\"heading-anchor\" href=\"#committing-guidelines\"><span class=\"visually-hidden\">Lien vers cette rubrique</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>En plus, veuillez suivre les lignes directrices suivantes lorsque vous envoyez des commits dans le dépôt Git de Django :</p>\n<ul>\n<li><p>Never change the published history of <code class=\"docutils literal notranslate\">django/django</code> branches by force\npushing. If you absolutely must (for security reasons for example), first\ndiscuss the situation with the team.</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 internal\" href=\"/fr/2.1/internals/mailing-lists/#django-developers-mailing-list\"><span class=\"std std-ref\">django-developers</span></a>\nmailing list before making the change.</p>\n<p>If you bring something up on <a class=\"reference internal\" href=\"/fr/2.1/internals/mailing-lists/#django-developers-mailing-list\"><span class=\"std std-ref\">django-developers</span></a> and nobody responds,\nplease don’t take that to mean your idea is great and should be\nimplemented immediately because nobody contested it. Everyone doesn’t always\nhave a lot of time to read mailing list discussions immediately, so you may\nhave to wait a couple of days before getting a response.</p>\n</li>\n<li><p>Écrivez les messages de commit détaillés au passé, pas au présent.</p>\n<ul class=\"simple\">\n<li><p>Juste : « Fixed Unicode bug in RSS API. »</p></li>\n<li><p>Faux : « Fixes Unicode bug in RSS API. »</p></li>\n<li><p>Faux : « Fixing Unicode bug in RSS API. »</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. In the\nbody of the commit message more detail is better than less:</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</code></pre></div>\n<p>If the patch wasn’t a pull request, you should credit the contributors in\nthe commit message: « Thanks A for report, B for the patch and C for the\nreview. »</p>\n</li>\n<li><p>For commits to a branch, prefix the commit message with the branch name.\nFor example: « [1.4.x] Fixed #xxxxx – Added support for mind reading. »</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=\"/fr/2.1/internals/release-process/#supported-versions-policy\"><span class=\"std std-ref\">Versions prises en charge</span></a>.</p></li>\n<li><p>If your commit closes a ticket in the Django <a class=\"reference external\" href=\"https://code.djangoproject.com/\">ticket tracker</a>, begin\nyour commit message with the text « Fixed #xxxxx », where « xxxxx » is the\nnumber of the ticket your commit fixes. Example: « Fixed #123 – Added\nwhizbang feature. ». We’ve rigged Trac so that any commit message in that\nformat will automatically close the referenced ticket and post a comment\nto it with the full commit message.</p>\n<p>Pour les curieux, nous utilisons un <a class=\"reference external\" href=\"https://github.com/trac-hacks/trac-github\">greffon Trac</a> pour cela.</p>\n</li>\n</ul>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</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 also close the same numbered ticket in Trac.</p>\n</aside>\n<ul>\n<li><p>If your commit references a ticket in the Django <a class=\"reference external\" href=\"https://code.djangoproject.com/\">ticket tracker</a> but\ndoes <em>not</em> close the ticket, include the phrase « Refs #xxxxx », where « xxxxx »\nis the number of the ticket your commit references. This will automatically\npost a comment to the appropriate ticket.</p></li>\n<li><p>Write commit messages for backports using this pattern:</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>Par exemple :</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 master.\n</code></pre></div>\n<p>Il existe un script dans le wiki &lt;<a class=\"reference external\" href=\"https://code.djangoproject.com/wiki/CommitterTips#AutomatingBackports\">https://code.djangoproject.com/wiki/CommitterTips#AutomatingBackports</a>&gt;`_ pour automatiser cela.</p>\n<p>Si le commit corrige une régression, incluez ceci dans le message de commit :</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>(utilisez l’empreinte du commit où la régression a été introduite).</p>\n</li>\n</ul>\n</section>\n<section id=\"reverting-commits\">\n<h2>Annulation de commits<a class=\"heading-anchor\" href=\"#reverting-commits\"><span class=\"visually-hidden\">Lien vers cette rubrique</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Personne n’est parfait ; des erreurs seront forcément commises.</p>\n<p>Mais faites tout votre possible pour que de telles erreurs ne se produisent pas. Le fait d’avoir une politique d’annulation ne vous enlève pas la responsabilité de viser la plus haute qualité possible. Sérieusement, vérifiez votre travail autant de fois que nécessaire ou faites-le vérifier par un autre commiteur <strong>avant</strong> de procéder au commit !</p>\n<p>Lorsqu’un commit fautif est découvert, veuillez suivre les directives suivantes :</p>\n<ul class=\"simple\">\n<li><p>Si possible, faites faire l’annulation d’un commit par son auteur.</p></li>\n<li><p>N’annulez pas les modifications d’un autre auteur sans la permission de celui-ci.</p></li>\n<li><p>Utilisez <code class=\"docutils literal notranslate\">git revert</code> – ce qui va produire un commit d’annulation, le commit original faisant toujours partie de l’historique des commits.</p></li>\n<li><p>Si l’auteur d’origine ne peut pas être contacté (dans un espace de temps raisonnable, un à deux jours) et que le problème est sérieux (bogue de plantage, échecs de tests majeurs, etc.), demandez sur la liste de diffusion <a class=\"reference internal\" href=\"/fr/2.1/internals/mailing-lists/#django-developers-mailing-list\"><span class=\"std std-ref\">django-developers</span></a> s’il y a des oppositions puis procédez à l’annulation s’il n’y en a pas.</p></li>\n<li><p>Si le problème est mineur (par ex. un commit de fonctionnalité après le gel des fonctionnalités), attendez encore un peu.</p></li>\n<li><p>S’il y a désaccord entre le commiteur et celui qui propose l’annulation, il s’agit de résoudre le conflit sur la liste de diffusion <a class=\"reference internal\" href=\"/fr/2.1/internals/mailing-lists/#django-developers-mailing-list\"><span class=\"std std-ref\">django-developers</span></a>. Si aucun accord n’est trouvé, la décision doit alors être soumise à un vote.</p></li>\n<li><p>Si le commit a introduit une vulnérabilité de sécurité confirmée et révélée, le commit peut être immédiatement annulé sans obtenir de permission supplémentaire.</p></li>\n<li><p>The release branch maintainer may back out commits to the release\nbranch without permission if the commit breaks the release branch.</p></li>\n<li><p>If you mistakenly push a topic branch to <code class=\"docutils literal notranslate\">django/django</code>, just delete it.\nFor instance, if you did: <code class=\"docutils literal notranslate\">git push upstream feature_antigravity</code>,\njust do a reverse push: <code class=\"docutils literal notranslate\">git push upstream :feature_antigravity</code>.</p></li>\n</ul>\n</section>","rootId":"committing-code","toc":[{"title":"Gestion des requêtes de contribution","anchor":"handling-pull-requests","children":[]},{"title":"Lignes directrices pour les commits","anchor":"committing-guidelines","children":[]},{"title":"Annulation de commits","anchor":"reverting-commits","children":[]}],"breadcrumbs":[{"docname":"internals/index","title":"Fonctionnement interne du projet Django","url":"/fr/2.1/internals/"},{"docname":"internals/contributing/index","title":"Contribuer à Django","url":"/fr/2.1/internals/contributing/"}],"prev":{"docname":"internals/contributing/localizing","title":"Traduction de Django","url":"/fr/2.1/internals/contributing/localizing/"},"next":{"docname":"internals/mailing-lists","title":"Listes de diffusion","url":"/fr/2.1/internals/mailing-lists/"},"formats":{"html":"/fr/2.1/internals/contributing/committing-code/","markdown":"/fr/2.1/internals/contributing/committing-code.md","json":"/fr/2.1/internals/contributing/committing-code.json"},"source":"https://github.com/django/django/blob/stable/2.1.x/docs/internals/contributing/committing-code.txt","official":"https://docs.djangoproject.com/fr/2.1/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","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}