Accueil·Commandes du terminal

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

OptionSignification
--checkreport whether it would apply, change nothing
-3fall back to a three-way merge and leave conflict markers
--indexapply to the working tree and stage it
--cachedapply to the index only
-Rapply in reverse, undoing the patch
-p<n>strip n leading path components
--statshow what the patch touches

Exemples

git apply --check fix.patch

tells you if it fits before you try

git apply -3 fix.patch

applies it and leaves conflicts to resolve by hand

git apply -R fix.patch

takes 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