Cosa otterrai
Farai cherry-pick di un singolo commit, di un range e di un merge da un branch a un altro.
Configurare 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"
Passo 1: identificare il commit
git log feature --oneline
Passo 2: cherry-pick
git checkout release/1.0
git cherry-pick def5678
Passo 3: registrare la lineage
git cherry-pick -x def5678
Passo 4: cherry-pick di un range
git cherry-pick def5678..abc1234
git cherry-pick def5678^..abc1234
Passo 5: gestire conflitti
git cherry-pick <sha>
git add <file>
git cherry-pick --continue
git cherry-pick --abort
Passo 6: cherry-pick vuoti
git cherry-pick --allow-empty <sha>
git cherry-pick --skip
Passo 7: cherry-pick di un merge
git cherry-pick -m 1 <merge-sha>
Passo 8: verificare
git log --oneline
git diff main release/1.0
Workflow comuni
Backport hotfix
git checkout release/1.4
git cherry-pick -x <hotfix-sha>
git push
Salvataggio da un branch da buttare
git checkout main
git cherry-pick <valuable-sha>
git branch -D experimental
Inoltro fix tra linee di manutenzione
for branch in release/1.4 release/1.5 main; do
git checkout $branch
git cherry-pick -x <fix-sha>
done
Insidie
- Commit duplicati.
- Contesto perso.
- Cherry-pick ripetuti.