Accueil·Commandes du terminal

git cherry-pick

git

Syntaxe

git cherry-pick [-x] <commit>...

Copie un seul commit sur la branche courante sous un nouveau hachage ; fusionner cette branche plus tard peut donc faire apparaître deux fois la même modification.

Options courantes

OptionSignification
-xnote the original hash in the new message
-napply and stage without committing
-eedit the message
-m <parent>pick a merge commit, choosing a side
<a>..<b>a range; a itself is not included
--continuego on after a conflict
--abortundo the whole pick

Exemples

git cherry-pick a1b2c3d

copies that commit onto the current branch with a new hash

git cherry-pick -x a1b2c3d

same, with the source hash recorded in the message

git cherry-pick a1b2c3d^..d4e5f6a

copies a range, this time including a1b2c3d

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 cherry-pick ?

Copie un seul commit sur la branche courante sous un nouveau hachage ; fusionner cette branche plus tard peut donc faire apparaître deux fois la même modification.

Q. Comment l’écrire ?

git cherry-pick [-x] <commit>... — 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-cherry-pick