Git
Cherry-Pick
Version Control
Software Development
Code Management

Git Cherry-Pick to working copy without commit

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

git cherry-pick usually copies a commit and creates a new commit immediately. When you need the changes but want to edit, split, or combine them first, use no-commit mode. This keeps the patch in your index and working tree so you can shape history intentionally instead of accepting the source commit boundaries as-is.

Core Command

Use --no-commit, or short form -n.

bash
git cherry-pick --no-commit <commit-hash>

Effect:

  • Patch from source commit is applied.
  • No new commit is created automatically.
  • You can inspect and modify before final commit.

This is ideal for backports where source commit needs adaptation.

Basic Workflow

Start from clean working tree.

bash
git switch release/2026.03
git status

Apply without commit:

bash
git cherry-pick -n a1b2c3d

Review what changed:

bash
git diff
git diff --staged

Then commit with your own message:

bash
git commit -m "Backport bug fix for token refresh"

Starting from a clean working tree matters more here than in normal editing. If unrelated local changes are already present, it becomes hard to tell which lines came from the cherry-picked patch and which lines were already yours.

Combine Multiple Source Commits into One

No-commit mode is useful when you want one consolidated commit from several upstream commits.

bash
1git cherry-pick -n a1b2c3d
2git cherry-pick -n d4e5f6a
3git cherry-pick -n 7778889
4
5git commit -m "Backport auth stability fixes"

This keeps release history concise while still preserving functionally related changes.

For traceability, include original hashes in commit body:

text
cherry-picked-from: a1b2c3d
a1b2c3d d4e5f6a 7778889

Split One Source Commit into Several Destination Commits

Sometimes source commit mixes unrelated concerns. Apply once, then stage selectively.

bash
1git cherry-pick -n a1b2c3d
2git reset
3
4git add -p
5git commit -m "Backport API validation fix"
6
7git add -p
8git commit -m "Backport logging cleanup"

git add -p lets you build clean, focused commits from one imported patch.

Conflict Handling in No-Commit Mode

Conflicts can occur just like normal cherry-pick.

Conflict resolution sequence:

  1. Edit conflicted files.
  2. Stage resolved files with git add.
  3. Continue cherry-pick operation.
bash
git add src/auth/service.ts
git cherry-pick --continue

If the pick is not desired, abort cherry-pick state:

bash
git cherry-pick --abort

After successful continue in no-commit mode, Git still does not auto-create final commit, so you remain in control.

Cherry-Picking Merge Commits

If source commit is a merge commit, you must choose mainline parent.

bash
git cherry-pick -n -m 1 <merge-commit-hash>

Without -m, Git cannot determine which side of merge to replay. Use this carefully and verify patch intent with tests.

Verification Before Final Commit

Recommended checks before commit:

bash
git show --stat <commit-hash>
git diff --staged
git status

Then run targeted tests for touched areas. Backport errors are often subtle because context differs from source branch.

Preview Patch Before Applying

When you are not sure whether a commit should be imported, inspect it before cherry-picking. This avoids unnecessary conflict resolution and reduces cleanup work.

bash
git show --name-status <commit-hash>
git show <commit-hash>

If only part of the commit is needed, no-commit mode plus patch staging is usually cleaner than copying edits manually across files.

This workflow is also helpful when backporting into older branches where some parts of the commit apply cleanly and others need adaptation. You preserve Git level traceability without surrendering control over the final shape.

Common Pitfalls

  • Forgetting -n and creating immediate commit. Fix by using no-commit flag explicitly for editable imports.
  • Starting from dirty working tree. Fix by cleaning or stashing local work before cherry-pick.
  • Combining unrelated changes accidentally. Fix by reviewing staged diff and using patch staging.
  • Omitting provenance in final commit message. Fix by recording source commit hash references.
  • Mishandling merge commits without -m. Fix by selecting correct mainline parent and validating behavior.

Summary

  • git cherry-pick -n applies commit changes without auto-commit.
  • It is ideal for combining, splitting, or adjusting imported patches.
  • Conflict handling remains the same as regular cherry-pick.
  • Mainline selection is required for cherry-picking merge commits.
  • Review staged diff and run tests before writing the final commit.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.