git cherry-pick
`git cherry-pick` applies a specific commit from one branch onto another, without merging the entire branch. It's useful when you need just one fix or feature from another branch.
Cherry-picking creates a new commit with the same changes but a different hash, since it's technically a new commit on the target branch.
git cherry-pick <commit-hash>Picking a single commit
Run `git cherry-pick commit-hash` while on the target branch to apply just that one commit's changes on top of your current branch.
Handling conflicts
If the cherry-picked commit conflicts with your current branch, Git pauses so you can resolve conflicts manually, then continue with `git cherry-pick --continue`.
git switch main
git cherry-pick 9c2e1aa[main 3e8f1cc] Fix crash when cart is empty
Date: ...Applies the single commit 9c2e1aa from another branch onto main as a new commit.
git cherry-pick --continue[main 4a9d2bb] Fix crash when cart is emptyContinues a cherry-pick after manually resolving a conflict caused by the picked commit.
Key points
- git cherry-pick applies one specific commit onto another branch.
- It creates a new commit with a different hash on the target branch.
- Conflicts during cherry-pick must be resolved manually.
- It's useful for backporting a single fix without merging a whole branch.
