← Back to Mission Control

Selective Updates

6 min read

Cherry Picking

Mission Phase 25 • Difficulty: Intermediate

Picking Individual Commits

Merging brings over an entire branch. Sometimes you only need one commit—a single bug fix or a specific improvement. git cherry-pick copies an individual commit from one branch and applies it to another.

Basic Cherry-Pick

# Find the commit you want
git log --oneline feature-branch

# Apply it to your current branch
git cherry-pick abc123

Git creates a new commit on your current branch with the same changes and message. The new commit has a different hash because it has a different parent.

Cherry-Picking Multiple Commits

# Pick several specific commits
git cherry-pick abc123 def456

# Pick a range (older..newer, excludes abc123)
git cherry-pick abc123..ghi789

Common Use Cases

Useful Options

git cherry-pick -x abc123        # Record the original commit hash in the message
git cherry-pick --no-commit abc123  # Apply changes without committing
git cherry-pick --edit abc123    # Edit the commit message before committing

The -x flag is especially useful on shared branches—it documents where the change came from.

Handling Conflicts

Cherry-picks can conflict just like merges. Resolve them the same way:

  1. Fix the conflicts in the affected files
  2. Stage them with git add
  3. Continue with git cherry-pick --continue

Or abandon the operation entirely:

git cherry-pick --abort

A Word of Caution

Duplicate Commits Ahead

Cherry-picking creates a copy of a commit, not a link to it. If you later merge the original branch, the same change may appear twice in your history. Prefer merging or rebasing for routine integration—reserve cherry-pick for targeted, surgical updates.

Best Practices

Next: Temporal Storage

You can now transplant individual commits between timelines. Next, learn git stash—a place to safely park unfinished work while you switch contexts.