git diff
git
Syntaxe
git diff [--staged] [<commit>] [-- <path>]N'affiche que les modifications non encore indexées : après un git add, cela paraît vide, il faut alors --staged.
Options courantes
| Option | Signification |
|---|---|
| --staged | compare the staged snapshot with HEAD (same as --cached) |
| --stat | summary of files and line counts instead of the patch |
| -w | ignore whitespace changes |
| --name-only | list changed paths only |
| <a>...<b> | changes on b since it forked from a |
| -- <path> | restrict to a path; the -- keeps it from being read as a branch |
Exemples
git diffshows only what is NOT staged yet
git diff --stagedshows what git commit would record
git diff main...featurethe work feature added since it left main
Ce qui embrouille, c’est qu’annuler a plusieurs formes : déplacer là où pointe une branche n’est pas ajouter un commit qui l’inverse.
Comment lire
- Les crochets [ ] marquent une partie facultative.
- Les points de suspension … signifient qu’on peut en mettre plusieurs.
- Les options sont sensibles à la casse : sur certaines commandes, -r et -R ne font pas la même chose.
Questions fréquentes
Q. Que fait git diff ?
N'affiche que les modifications non encore indexées : après un git add, cela paraît vide, il faut alors --staged.
Q. Comment l’écrire ?
git diff [--staged] [<commit>] [-- <path>] — les crochets marquent ce qui est facultatif.
Q. Combien d’options valent la peine ?
Il y en a 6 ici ; la liste complète est dans man git. Cette commande relève de git.
Commandes liées
page man: man git-diff