Skip to content

Cherry-pick quick reference ​

Basic ​

CommandPurpose
git cherry-pick <sha>Apply one commit to HEAD
git cherry-pick -x <sha>Add (cherry picked from ...) trailer
git cherry-pick -s -x <sha>Sign off + trailer
git cherry-pick -n <sha>Apply diff without committing (staging)
git cherry-pick -m 1 <merge-sha>Pick changes from a merge (first parent)

Multiple commits ​

bash
git cherry-pick -x A^..D        # A through D
git cherry-pick -x sha1 sha2    # explicit list, oldest first

Conflict recovery ​

bash
# Resolve files, then:
git add <file>
git cherry-pick --continue   # proceed
git cherry-pick --skip       # drop this commit, continue sequence
git cherry-pick --abort      # cancel entirely

DevOps patterns ​

bash
# Backport to multiple release branches
for b in release/1.x release/2.x; do
  git checkout "$b" && git cherry-pick -x "$FIX_SHA"
done

# Promote through environments
git checkout prod && git cherry-pick -x staging~2..staging

# Verify fidelity after backport
git range-diff main~1..main HEAD~1..HEAD

Common flags ​

FlagUse
-xTrailer for traceability — use every backport
-nStage only, no commit
-eForce message editor
-m <n>Mainline parent for merge commits
--allow-emptyAllow zero-diff commits
--strategy=recursive -X theirsAuto-resolve conflicts toward the picked diff

Git Master — Git Reference for Every Skill Level