Middle
What is cherry-pick?
sobes.tech AI
Answer from AI
Cherry-pick is a Git operation that allows applying changes from one or more commits from one branch to another.
Main features:
- Allows selective transfer of commits.
- Creates new commits in the target branch with the same changes as the original ones.
- May lead to conflicts that need to be resolved manually.
Typical usage scenarios:
- Fixing bugs in the release branch when the fix was developed in the development branch.
- Transferring individual features or fixes between branches without affecting other changes.
Process:
- Find the hash (SHA) of the commit(s) that need cherry-pick.
- Switch to the target branch.
- Execute the command
git cherry-pick <commit-hash>. - If conflicts occur, resolve them and finish the cherry-pick (
git add .,git cherry-pick --continue). - To cherry-pick multiple commits, specify them separated by spaces or use a range
git cherry-pick <commit-hash-start>..<commit-hash-end>.
Example commands:
# Apply a single commit
git cherry-pick a1b2c3d4
# Apply multiple commits
git cherry-pick a1b2c3d4 e5f6g7h8
# Apply a range of commits (excluding the start commit)
git cherry-pick a1b2c3d4..e5f6g7h8