Cherry-Picking Commits
git cherry-pick, apply specific commit, cherry-pick range, cherry-pick use cases, conflicts during cherry-pick
Cherry-Picking Commits
Cherry-picking applies the changes from a specific commit (or range of commits) onto the current branch without merging the entire source branch. It is used for targeted backporting of fixes and transferring isolated changes between branches.
Basic Cherry-Pick
git cherry-pick abc1234This takes the changes introduced by commit abc1234 and applies them as a new commit on your current branch. The new commit has a different hash but the same changes and message as the original.
Cherry-Picking a Range
git cherry-pick abc1234..def5678This applies all commits from (but not including) abc1234 up to and including def5678.
Cherry-Pick Without Committing
git cherry-pick --no-commit abc1234This applies the changes to the working directory and staging area but does not create a commit. Useful when you want to combine changes from multiple cherry-picks into one commit.
Common Use Cases
Cherry-pick is ideal for: backporting a critical bug fix from a development branch to a release branch, applying a single useful commit from a feature branch that was abandoned, and recovering a commit that was accidentally made on the wrong branch.
Handling Conflicts
If a conflict occurs during cherry-pick, resolve it just like a merge conflict: edit the file, remove conflict markers, stage it, then run git cherry-pick --continue. Use git cherry-pick --abort to cancel.
