Ce que vous accomplirez
Vous ferez cherry-pick d'un commit unique, d'une plage et d'un merge d'une branche à une autre, en gérant les conflits.
Configurer un sandbox
mkdir cherry-tutorial && cd cherry-tutorial
git init
echo "v1" > app.txt
git add . && git commit -m "Initial"
git checkout -b release/1.0
echo "release" > release.txt
git add . && git commit -m "Release notes"
git checkout main
git checkout -b feature
echo "fix" > fix.txt
git add . && git commit -m "Critical bug fix"
echo "feat" > feat.txt
git add . && git commit -m "New feature work"
Étape 1 : identifier le commit
git log feature --oneline
Étape 2 : cherry-pick
git checkout release/1.0
git cherry-pick def5678
Étape 3 : enregistrer la lignée
git cherry-pick -x def5678
Étape 4 : cherry-pick d'une plage
git cherry-pick def5678..abc1234
git cherry-pick def5678^..abc1234
Étape 5 : gérer les conflits
git cherry-pick <sha>
git add <file>
git cherry-pick --continue
git cherry-pick --abort
Étape 6 : cherry-picks vides
git cherry-pick --allow-empty <sha>
git cherry-pick --skip
Étape 7 : cherry-pick d'un merge
git cherry-pick -m 1 <merge-sha>
Étape 8 : vérifier
git log --oneline
git diff main release/1.0
Workflows courants
Back-port de hotfix
git checkout release/1.4
git cherry-pick -x <hotfix-sha>
git push
Sauvetage d'une branche que vous jetterez
git checkout main
git cherry-pick <valuable-sha>
git branch -D experimental
Faire suivre les fixes entre lignes de maintenance
for branch in release/1.4 release/1.5 main; do
git checkout $branch
git cherry-pick -x <fix-sha>
done
Pièges
- Commits dupliqués.
- Contexte perdu.
- Cherry-picking répété.