Lesson 46 +20 XP

Cherry Pick

Git Cherry Pick

git cherry-pick copies a specific commit from one branch and applies it to the branch you are on.

The cherry-pick command

git cherry-pick abc123

This takes commit abc123 from anywhere in your history and applies it as a new commit on your current branch.

Why cherry-pick?

  • Bring one fix to a release branch without merging everything else.
  • Copy a single commit from another feature branch.
  • Reuse a hotfix in several places.

The result

The new commit has a new hash (it is a copy), and often a "cherry picked from" line in the message.

Cherry pick a range

git cherry-pick startHash..endHash

This applies all the commits in that range.

Conflicts can happen

If the copied change conflicts with your branch, Git pauses and asks you to resolve it, then finish with:

git cherry-pick --continue

TL;DR

  • git cherry-pick hash applies one commit to your current branch.
  • Great for moving a single fix between branches.
  • The copied commit gets a new hash.
  • Resolve conflicts, then run git cherry-pick --continue.