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
| Option | Signification |
|---|---|
| -x | note the original hash in the new message |
| -n | apply and stage without committing |
| -e | edit the message |
| -m <parent> | pick a merge commit, choosing a side |
| <a>..<b> | a range; a itself is not included |
| --continue | go on after a conflict |
| --abort | undo the whole pick |
Exemples
git cherry-pick a1b2c3dcopies that commit onto the current branch with a new hash
git cherry-pick -x a1b2c3dsame, with the source hash recorded in the message
git cherry-pick a1b2c3d^..d4e5f6acopies 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