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.
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.
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.
Apply without commit:
Review what changed:
Then commit with your own message:
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.
This keeps release history concise while still preserving functionally related changes.
For traceability, include original hashes in commit body:
Split One Source Commit into Several Destination Commits
Sometimes source commit mixes unrelated concerns. Apply once, then stage selectively.
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:
- Edit conflicted files.
- Stage resolved files with
git add. - Continue cherry-pick operation.
If the pick is not desired, abort cherry-pick state:
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.
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:
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.
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
-nand 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 -napplies 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
- Git Cherry-pick vs Merge Workflow
- Git clone changes file modification time
- GIT clone repo across local file system in windows
- git clone through ssh
- git clone with different username/account
- git clone with HTTPS or SSH remote?
- Git command to display HEAD commit id?
- Git command to show which specific files are ignored by .gitignore
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.