---
title: "Commit de code"
version: 2.1
locale: fr
source: https://docs.djangoproject.com/fr/2.1/internals/contributing/committing-code/
canonical: https://djangodocs.dev/fr/2.1/internals/contributing/committing-code/
---
# Commit de code

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 [Travailler avec Git et GitHub](/fr/2.1/internals/contributing/writing-code/working-with-git/).

## Gestion des requêtes de contribution

Comme Django est hébergé sur GitHub, la plupart des correctifs sont fournis sous la forme de requêtes de contribution (« pull request »).

When committing a pull request, make sure each individual commit matches the
commit guidelines described below. Contributors are expected to provide the
best pull requests possible. In practice however, committers - who will likely
be more familiar with the commit guidelines - may decide to bring a commit up
to standard themselves.

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 [page de Wiki de Jenkins](https://code.djangoproject.com/wiki/Jenkins) pour plus d’instructions.

Une façon simple de récupérer localement une requête de contribution est d’ajouter un alias à votre fichier `~/.gitconfig` (en supposant que `upstream` correspond à `django/django`) :

```
[alias]
    pr = !sh -c \"git fetch upstream pull/${1}/head:pr/${1} && git checkout pr/${1}\"
```

Vous pouvez maintenant simplement exécuter `git pr ####` pour récupérer en local la requête de contribution correspondante.

À ce stade, vous pouvez travailler sur le code. Utilisez `git rebase -i` et `git commit --amend` pour vous assurer que les commits présentent le niveau de qualité requis. Quand vous êtes prêt :

```console
$ # Pull in the latest changes from master.
$ git checkout master
$ git pull upstream master
$ # Rebase the pull request on master.
$ git checkout pr/####
$ git rebase master
$ git checkout master
$ # Merge the work as "fast-forward" to master to avoid a merge commit.
$ # (in practice, you can omit "--ff-only" since you just rebased)
$ git merge --ff-only pr/XXXX
$ # If you're not sure if you did things correctly, check that only the
$ # changes you expect will be pushed to upstream.
$ git push --dry-run upstream master
$ # Push!
$ git push upstream master
$ # Delete the pull request branch.
$ git branch -d pr/xxxx
```

*Windows*

```doscon
...\> REM Pull in the latest changes from master.
...\> git checkout master
...\> git pull upstream master
...\> REM Rebase the pull request on master.
...\> git checkout pr/####
...\> git rebase master
...\> git checkout master
...\> REM Merge the work as "fast-forward" to master to avoid a merge commit.
...\> REM (in practice, you can omit "--ff-only" since you just rebased)
...\> git merge --ff-only pr/XXXX
...\> REM If you're not sure if you did things correctly, check that only the
...\> REM changes you expect will be pushed to upstream.
...\> git push --dry-run upstream master
...\> REM Push!
...\> git push upstream master
...\> REM Delete the pull request branch.
...\> git branch -d pr/xxxx
```

Force push to the branch after rebasing on master but before merging and
pushing to upstream. This allows the commit hashes on master and the branch to
match which automatically closes the pull request.

If a pull request doesn’t need to be merged as multiple commits, you can use
GitHub’s « Squash and merge » button on the website. Edit the commit message as
needed to conform to [the guidelines](#committing-guidelines) and remove
the pull request number that’s automatically appended to the message’s first
line.

When rewriting the commit history of a pull request, the goal is to make
Django’s commit history as usable as possible:

- If a patch contains back-and-forth commits, then rewrite those into one.
  For example, if a commit adds some code and a second commit fixes stylistic
  issues introduced in the first commit, those commits should be squashed
  before merging.
- Separate changes to different commits by logical grouping: if you do a
  stylistic cleanup at the same time as you do other changes to a file,
  separating the changes into two different commits will make reviewing
  history easier.
- Beware of merges of upstream branches in the pull requests.
- Tests should pass and docs should build after each commit. Neither the
  tests nor the docs should emit warnings.
- Trivial and small patches usually are best done in one commit. Medium to
  large work may be split into multiple commits if it makes sense.

Practicality beats purity, so it is up to each committer to decide how much
history mangling to do for a pull request. The main points are engaging the
community, getting work done, and having a usable commit history.

## Lignes directrices pour les commits

En plus, veuillez suivre les lignes directrices suivantes lorsque vous envoyez des commits dans le dépôt Git de Django :

- Never change the published history of `django/django` branches by force
  pushing. If you absolutely must (for security reasons for example), first
  discuss the situation with the team.
- For any medium-to-big changes, where « medium-to-big » is according to
  your judgment, please bring things up on the [django-developers](/fr/2.1/internals/mailing-lists/#django-developers-mailing-list)
  mailing list before making the change.

  If you bring something up on [django-developers](/fr/2.1/internals/mailing-lists/#django-developers-mailing-list) and nobody responds,
  please don’t take that to mean your idea is great and should be
  implemented immediately because nobody contested it. Everyone doesn’t always
  have a lot of time to read mailing list discussions immediately, so you may
  have to wait a couple of days before getting a response.
- Écrivez les messages de commit détaillés au passé, pas au présent.

  - Juste : « Fixed Unicode bug in RSS API. »
  - Faux : « Fixes Unicode bug in RSS API. »
  - Faux : « Fixing Unicode bug in RSS API. »

  The commit message should be in lines of 72 chars maximum. There should be
  a subject line, separated by a blank line and then paragraphs of 72 char
  lines. The limits are soft. For the subject line, shorter is better. In the
  body of the commit message more detail is better than less:

  ```
  Fixed #18307 -- Added git workflow guidelines

  Refactored the Django's documentation to remove mentions of SVN
  specific tasks. Added guidelines of how to use Git, GitHub, and
  how to use pull request together with Trac instead.
  ```

  If the patch wasn’t a pull request, you should credit the contributors in
  the commit message: « Thanks A for report, B for the patch and C for the
  review. »
- For commits to a branch, prefix the commit message with the branch name.
  For example: « \[1.4.x\] Fixed #xxxxx – Added support for mind reading. »
- Limit commits to the most granular change that makes sense. This means,
  use frequent small commits rather than infrequent large commits. For
  example, if implementing feature X requires a small change to library Y,
  first commit the change to library Y, then commit feature X in a separate
  commit. This goes a *long way* in helping everyone follow your changes.
- Separate bug fixes from feature changes. Bugfixes may need to be backported
  to the stable branch, according to [Versions prises en charge](/fr/2.1/internals/release-process/#supported-versions-policy).
- If your commit closes a ticket in the Django [ticket tracker](https://code.djangoproject.com/), begin
  your commit message with the text « Fixed #xxxxx », where « xxxxx » is the
  number of the ticket your commit fixes. Example: « Fixed #123 – Added
  whizbang feature. ». We’ve rigged Trac so that any commit message in that
  format will automatically close the referenced ticket and post a comment
  to it with the full commit message.

  Pour les curieux, nous utilisons un [greffon Trac](https://github.com/trac-hacks/trac-github) pour cela.

> **Note**
>
> Note that the Trac integration doesn’t know anything about pull requests.
> So if you try to close a pull request with the phrase « closes #400 » in your
> commit message, GitHub will close the pull request, but the Trac plugin
> will also close the same numbered ticket in Trac.

- If your commit references a ticket in the Django [ticket tracker](https://code.djangoproject.com/) but
  does *not* close the ticket, include the phrase « Refs #xxxxx », where « xxxxx »
  is the number of the ticket your commit references. This will automatically
  post a comment to the appropriate ticket.
- Write commit messages for backports using this pattern:

  ```
  [<Django version>] Fixed <ticket> -- <description>

  Backport of <revision> from <branch>.
  ```

  Par exemple :

  ```
  [1.3.x] Fixed #17028 -- Changed diveintopython.org -> diveintopython.net.

  Backport of 80c0cbf1c97047daed2c5b41b296bbc56fe1d7e3 from master.
  ```

  Il existe un script dans le wiki \<<https://code.djangoproject.com/wiki/CommitterTips#AutomatingBackports>\>\`\_ pour automatiser cela.

  Si le commit corrige une régression, incluez ceci dans le message de commit :

  ```
  Regression in 6ecccad711b52f9273b1acb07a57d3f806e93928.
  ```

  (utilisez l’empreinte du commit où la régression a été introduite).

## Annulation de commits

Personne n’est parfait ; des erreurs seront forcément commises.

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 **avant** de procéder au commit !

Lorsqu’un commit fautif est découvert, veuillez suivre les directives suivantes :

- Si possible, faites faire l’annulation d’un commit par son auteur.
- N’annulez pas les modifications d’un autre auteur sans la permission de celui-ci.
- Utilisez `git revert` – ce qui va produire un commit d’annulation, le commit original faisant toujours partie de l’historique des commits.
- 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 [django-developers](/fr/2.1/internals/mailing-lists/#django-developers-mailing-list) s’il y a des oppositions puis procédez à l’annulation s’il n’y en a pas.
- Si le problème est mineur (par ex. un commit de fonctionnalité après le gel des fonctionnalités), attendez encore un peu.
- 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 [django-developers](/fr/2.1/internals/mailing-lists/#django-developers-mailing-list). Si aucun accord n’est trouvé, la décision doit alors être soumise à un vote.
- 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.
- The release branch maintainer may back out commits to the release
  branch without permission if the commit breaks the release branch.
- If you mistakenly push a topic branch to `django/django`, just delete it.
  For instance, if you did: `git push upstream feature_antigravity`,
  just do a reverse push: `git push upstream :feature_antigravity`.
