git apply
git
Syntaxe
git apply [--check|-3] <patch>Applique un fichier diff à votre copie de travail ; il ne crée aucun commit et ignore l'auteur inscrit dans le correctif, les correctifs reçus par courriel relèvent donc de am.
Options courantes
| Option | Signification |
|---|---|
| --check | report whether it would apply, change nothing |
| -3 | fall back to a three-way merge and leave conflict markers |
| --index | apply to the working tree and stage it |
| --cached | apply to the index only |
| -R | apply in reverse, undoing the patch |
| -p<n> | strip n leading path components |
| --stat | show what the patch touches |
Exemples
git apply --check fix.patchtells you if it fits before you try
git apply -3 fix.patchapplies it and leaves conflicts to resolve by hand
git apply -R fix.patchtakes an applied patch back out
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 apply ?
Applique un fichier diff à votre copie de travail ; il ne crée aucun commit et ignore l'auteur inscrit dans le correctif, les correctifs reçus par courriel relèvent donc de am.
Q. Comment l’écrire ?
git apply [--check|-3] <patch> — les crochets marquent ce qui est facultatif.
Q. Combien d’options valent la peine ?
Il y en a 7 ici ; la liste complète est dans man git. Cette commande relève de git.
Commandes liées
page man: man git-apply