Git Cherry-Pick

Copy individual commits across branches without full merges.

  • git cherry-pick
  • backport
  • cherry pick range
  • copy commit
  • hotfix

Git Cherry-Pick

Copy individual commits across branches without full merges.

Commands

CommandWhat it does
git cherry-pick <commit>Apply one commit onto the current branch
git cherry-pick -n <commit>Apply to working tree without committing
git cherry-pick --abortCancel a conflicted cherry-pick
git cherry-pick --continueResume after resolving
git cherry-pick main~3..mainPick a commit range

Example

git switch release/1.2
git cherry-pick a1b2c3d  # backport hotfix
git push

FAQ

When is cherry-pick better than merge?

For backporting single hotfixes to release branches where merging whole feature history would be wrong.

Does cherry-pick preserve the commit hash?

No — it creates a new commit with a new hash; note the origin in the message for traceability.

Întrebări frecvente

When is cherry-pick better than merge?
For backporting single hotfixes to release branches where merging whole feature history would be wrong.
Does cherry-pick preserve the commit hash?
No — it creates a new commit with a new hash; note the origin in the message for traceability.

Git