Git cherry-pick = copiar UN commit concreto de una rama a otra.
Ejemplo concreto:
feature-login: commit de corrección de un bug críticomain: quieres SOLO esa corrección, no toda la ramagit cherry-pick <commit-hash>Creación del proyecto:
mkdir demo-cherry-pick && cd demo-cherry-pick
git init
echo "print('v1')" > app.py
git add . && git commit -m "Versión inicial"
# Crear la rama feature
git checkout -b feature-new
echo "print('v2-feature')" > app.py
git add . && git commit -m "Nueva funcionalidad"
echo "print('v2-bugfix')" > app.py
git add . && git commit -m "Fix critique"
# Volver a main y hacer cherry-pick SOLO del bugfix
git checkout main
git cherry-pick <hash-du-commit-bugfix>Listo. El arreglo está en main, sin la funcionalidad.
Situación típica:
feature-branchmain) necesita el arreglo YASolución:
git log --oneline feature-branch # Encontrar el hash del arreglo
git checkout main
git cherry-pick abc123f # Aplicar SOLO ese commit| Comando | Acción |
|---|---|
git cherry-pick <hash> | Copiar un commit |
git cherry-pick <hash1> <hash2> | Copiar varios commits |
git cherry-pick --continue | Continuar tras resolver un conflicto |
git cherry-pick --abort | Cancelar la operación |
¡Eso es todo! Cherry-pick es simple: 1 commit → 1 copia.