The git cherry-pick command allows to apply one or several commit
from one branch to another, without merging the two branch.
It creates a new commit in the branch it’s apply to, with the same message of the commit in the other branch.
If we have two branches, main and dev. The dev branch has a bug fix commit we want to apply to the main, but we don’t want to apply the rest of the commit.
main
O
⎜
O dev
⎜ \
O O
⎜ ⎜
O O <- bug fix
⎜
O
git logmaingit cherry-pick (bug fix hash)
main
O
⎜
O dev
⎜ \
O O
⎜ ⎜
O O <- bug fix
⎜ ⎜
bug fix ->O O
Simply specify multiple commit hash
git cherry-pick hash1 hash2
It create a new commit for each hash, applying the changes in the order specify in the command.
Cherry pick can produce merge conflicts.
To resolve:
git status to see the files that need resolution.