Qué hace cherry-pick
git cherry-pick toma un commit de un branch y lo aplica como un nuevo commit en el branch actual. El commit original no cambia.
La operación básica
git checkout release/1.4
git cherry-pick <sha>
Cherry-pick de rangos
git cherry-pick <sha1> <sha2> <sha3>
git cherry-pick <older>..<newer>
git cherry-pick <older>^..<newer>
Cherry-pick con conflictos
git cherry-pick <sha>
git add <file>
git cherry-pick --continue
git cherry-pick --abort
Registrar el origen en el mensaje
git cherry-pick -x <sha>
Cherry-pick de merges
git cherry-pick -m 1 <merge-sha>
Cherry-pick vs merge
- Merge - integra un branch completo; preserva el enlace.
- Cherry-pick - copia un commit específico; sin enlace.
El problema de commits duplicados
git cherry main feature
git rebase --skip
Cherry-picks vacíos
git cherry-pick --allow-empty <sha>
git cherry-pick --skip
Workflows donde brilla cherry-pick
- Hotfix desde
mainhacia un branch release. - Promover un fix de un branch feature a
main. - Reaplicar un commit perdido durante un rebase.
Mejores prácticas
- Siempre usa
-xpara back-ports. - Referencia el PR fuente o ticket en el mensaje.
- Ejecuta tests en el branch destino.