Git Cherry-Pick: Selectively Applying Commits
Master git cherry-pick to selectively apply commits between branches. Learn use cases, pitfalls, and best practices for targeted commit transplantation.
Cherry-pick takes a specific commit from one branch and applies its changes as a new commit on your current branch, with a different SHA and parent. Use it for backporting bug fixes to release branches or extracting isolated commits from abandoned branches. Always use the -x flag to record the original commit for audit trails, and check for hidden dependencies before cherry-picking. Avoid using it as a regular workflow for merging feature branches; rebase and merge preserve commit relationships that cherry-pick duplicates.
Introduction
Cherry-picking is Git’s surgical tool for commit management. Instead of merging an entire branch or rebasing a series of commits, cherry-pick lets you select individual commits and apply them to a different branch. It’s the equivalent of saying “I want exactly this change, nothing else.”
This precision makes cherry-pick invaluable for specific scenarios — backporting bug fixes, extracting useful work from experimental branches, and applying hotfixes across multiple release lines. But it’s also one of the most misused Git commands, leading to duplicate commits, confusing histories, and merge conflicts.
Understanding when to cherry-pick and when to use other tools is the difference between a targeted fix and a historical mess. This guide covers the mechanics, the use cases, and the pitfalls.
When to Use / When Not to Use
When to Use Cherry-Pick
These scenarios share a common trait: you need a specific change but not the entire branch history. Cherry-pick works best when the commit you’re moving is self-contained and the target branch has diverged enough that merging would pull in unwanted changes.
- Backporting bug fixes — apply a fix from main to a maintenance release branch. The release branch is typically stable and close to shipping; merging main could introduce new features or breaking changes you don’t want. Cherry-pick lets you grab just the fix.
- Extracting useful commits — salvage good work from an abandoned experimental branch. When a feature branch goes stale or gets merged with unrelated changes, cherry-pick lets you rescue the commits that actually matter.
- Hotfix distribution — apply the same fix across multiple release branches. Running the same cherry-pick command on each release branch is faster than manually re-implementing the fix or managing multiple merge conflicts.
- Correcting mistakes — apply a commit you forgot to include in a previous merge. If you merged a branch but realized a critical commit was left behind, cherry-pick is faster than rebasing and safer than reverting and re-merging.
- Selective feature adoption — pull one specific feature from a large branch. When a team delivers a big branch but you only need one feature, cherry-picking that single commit avoids integrating everything else.
When Not to Use Cherry-Pick
Cherry-pick is a precision tool, not a general-purpose integration method. Reaching for it in the wrong context creates maintenance headaches that outlast the original problem.
- Regular feature integration — use merge or rebase instead. When you’re integrating a complete feature branch, merge or rebase preserves the full history and relationships between commits. Cherry-pick strips that context and leaves you with orphaned commits.
- Large sets of commits — cherry-picking many commits creates duplicate history. If you later merge the original branch, Git doesn’t recognize the changes are already present, leading to duplicate commits or conflicts. For more than three or four commits, consider merge or rebase.
- When you need the full branch context — cherry-pick loses branch relationships. Each cherry-picked commit is a standalone island. If a commit was designed to work with other commits around it, cherry-picking just one breaks the intended flow.
- As a substitute for proper branching — don’t cherry-pick to avoid learning merge/rebase. If you find yourself constantly cherry-picking commits between branches, it’s often a sign that your branching strategy needs rethinking. Merge and rebase exist for a reason.
- Commits with complex dependencies — if a commit depends on others, cherry-pick may break. A commit that adds a function and another that calls that function must be cherry-picked together. Cherry-picking only the second commit leaves you with broken code.
Core Concepts
Cherry-pick takes a commit from one branch and creates a new commit with the same changes on your current branch. The new commit has a different SHA but the same diff.
Before cherry-pick:
main: A ── B ── C ── D
\
feature: E ── F ── G
After cherry-picking F onto main:
main: A ── B ── C ── D ── F'
\
feature: E ── F ── G
F’ has the same changes as F but a different SHA and a different parent (D instead of E).
graph TD
Start["Identify commit to cherry-pick"] --> Find["git log --oneline\nor git reflog"]
Find --> Switch["git switch target-branch"]
Switch --> Apply["git cherry-pick <sha>"]
Apply --> Conflict{"Conflict?"}
Conflict -->|Yes| Resolve["Resolve, git add,\ngit cherry-pick --continue"]
Conflict -->|No| Done["New commit created\non current branch"]
Resolve --> Done
Architecture or Flow Diagram
flowchart TD
A["Source Branch:\ncommit F (bug fix)"] --> Identify["Identify commit SHA"]
B["Target Branch:\nrelease/v1.0"] --> Switch["git switch release/v1.0"]
Identify --> Cherry["git cherry-pick F"]
Switch --> Cherry
Cherry --> Result{"Result"}
Result -->|Clean| NewCommit["New commit F'\nSame changes, new SHA"]
Result -->|Conflict| ManualResolve["Resolve conflicts\nmanually"]
ManualResolve --> NewCommit
NewCommit --> Verify["Run tests\nVerify fix works"]
Verify --> Push["git push origin release/v1.0"]
Step-by-Step Guide / Deep Dive
Basic Cherry-Pick
The simplest form of cherry-pick takes a single commit SHA and applies its changes to your current branch. A SHA is the 7+ character identifier shown in git log --oneline output — for example, abc1234 or f0e9d8c. You can copy it directly from your history or from a remote repository’s commit log.
Beyond single commits, cherry-pick handles multiple commits in one command. Git applies them in the order you specify, which matters when commits have dependencies. If commit B modifies a function that commit A introduced, you must cherry-pick A before B. The range syntax (abc1234..def5678) is shorthand for “all commits after abc1234 up to and including def5678” — useful when you’ve identified a contiguous set of bug fixes or features to apply.
# Cherry-pick a single commit
git cherry-pick abc1234
# Cherry-pick multiple commits (in order)
git cherry-pick abc1234 def5678 ghi9012
# Cherry-pick a range of commits (inclusive)
git cherry-pick abc1234..def5678
# Cherry-pick a range including the start commit
git cherry-pick abc1234^..def5678
Cherry-Pick Options
Cherry-pick has several flags that change how it behaves. The most frequently used are --no-commit (or -n) and --edit (or -e) — these control whether you want to review the changes before Git creates a commit. Use -n when you want to inspect the diff, run tests on the staged changes, or modify the code before committing. Use -e when the changes are fine but the commit message needs editing.
The -x flag is useful for backporting and audit trails. It appends a line to the commit message recording the original SHA: (cherry picked from commit abc1234...). This makes it traceable later. The --signoff flag (-s) does something different — it adds your identity as the applier, which is required for some contribution workflows and DCO compliance.
When conflicts occur, cherry-pick stops and waits. You have two paths: --abort cancels the entire operation and restores the branch to its pre-cherry-pick state, or --continue resumes after you resolve the conflicts and stage the resolved files. There’s no auto-resolve; you must explicitly tell Git you’re done resolving.
# Apply changes but don't commit (stage only)
git cherry-pick --no-commit abc1234
# Edit the commit message before committing
git cherry-pick --edit abc1234
# Preserve the original commit message (add reference)
git cherry-pick -x abc1234
# Appends: (cherry picked from commit abc1234...)
# Apply without auto-committing (for review)
git cherry-pick -n abc1234
# Abort an in-progress cherry-pick
git cherry-pick --abort
# Continue after resolving conflicts
git cherry-pick --continue
Finding Commits to Cherry-Pick
Before you can cherry-pick, you need the SHA. git log is the primary tool, but plain git log shows everything. The --author filter narrows it to a specific contributor — useful when you know a colleague found and fixed a bug. The --grep flag searches commit messages for keywords, so searching for “bug fix” or a ticket ID like “JIRA-1234” finds relevant commits quickly.
The --path/to/file filter is underused. If you know the bug is in auth/service.go, you can list every commit that touched that file across all branches. Combined with --after and --before date filters, you can narrow down to a specific time window — useful when you remember the bug appeared around a certain release.
Once you find a candidate commit, git show <sha> displays the full diff and commit metadata. Always run this before cherry-picking. The diff shows exactly what changed; the metadata shows the author, date, and commit message. If the diff looks simple but the commit message references other commits or mentions “continuation of X”, the commit likely has dependencies that need cherry-picking together.
# Find commits by author
git log --author="username" --oneline
# Find commits that touched a specific file
git log --oneline -- path/to/file
# Find commits containing a keyword
git log --grep="bug fix" --oneline
# Find commits between two dates
git log --after="2026-03-01" --before="2026-03-31" --oneline
# Show the diff of a commit before cherry-picking
git show abc1234
Cherry-Picking Across Repositories
Most cherry-picking happens within a single repository, but sometimes you need to port a commit from an external project — a patch from an upstream library, a fix from a fork, or a contribution you want to apply without merging the entire remote branch. The workflow is straightforward but requires a temporary remote.
Add the source repository as a remote, fetch from it, then cherry-pick using the standard remote/branch~n syntax. The fetch brings down the commit objects without merging anything. After cherry-picking, you can remove the remote to keep your repository clean. The key thing to remember is that the fetched commits are local after the fetch — you can reference them with the remote name just like any other ref.
This differs from same-repository cherry-pick in one important way: the author attribution stays with the original commit, but Git considers you the committer on the new commit. If your project requires sign-off from the applier, use --signoff alongside --no-commit to add your identity.
# Add the source repository as a remote
git remote add source-repo https://github.com/other/repo.git
git fetch source-repo
# Cherry-pick from the fetched remote
git cherry-pick source-repo/main~3
# Clean up
git remote remove source-repo
Production Failure Scenarios
| Scenario | Impact | Mitigation |
|---|---|---|
| Cherry-picking dependent commits | Missing dependencies cause breakage | Review commit dependencies; cherry-pick in order |
| Duplicate commits in history | Same change appears with different SHAs | Use -x flag to track origin; document in PR |
| Cherry-pick conflicts on old branches | Code has diverged significantly | Test thoroughly; consider backporting manually |
| Losing original commit attribution | Author information may be lost | Use --signoff and -x to preserve attribution |
| Cherry-picking merge commits | Creates unexpected results | Use -m 1 to specify which parent to use |
Cherry-Picking Merge Commits
Merge commits are different from regular commits — they have two parents instead of one, and each parent represents a different line of history. When you cherry-pick a merge commit, Git needs to know which parent’s changes to diff against. The -m flag handles this.
A merge commit records the combination of two branches. When Git creates it, the first parent is the branch you were on when you ran git merge, and the second parent is the branch being merged. If you want to apply the merge commit to another branch, you have to tell Git which set of changes you actually want: the ones from the branch you were on, or the ones from the branch that was merged in.
Without -m, Git doesn’t know how to compute the diff and will error out. With -m 1, Git diffs against the first parent — the branch you were on when the merge happened. With -m 2, Git diffs against the second parent — the branch that was merged in. The two choices give you different changes: -m 1 gives you what happened on your branch leading up to the merge, while -m 2 gives you what happened on the merged branch.
# Cherry-pick a merge commit (specify which parent to diff against)
git cherry-pick -m 1 <merge-commit-sha>
# -m 1: diff against first parent (usually the branch you were on)
# -m 2: diff against second parent (the merged branch)
This flag is easy to forget, which is why cherry-picking merge commits is considered an advanced operation. If you get it wrong, you might apply the wrong half of a merge or create conflicts that shouldn’t exist. Always check which parent has the changes you actually want to move.
Trade-off Analysis
| Approach | Pros | Cons |
|---|---|---|
| Cherry-pick | Targeted, precise, flexible | Creates duplicate commits, loses context |
| Merge | Preserves relationships, single source of truth | Brings entire branch, may include unwanted changes |
| Rebase | Clean history, linear | Rewrites history, not for shared branches |
| Manual backport | Full control, can adapt changes | Time-consuming, error-prone |
| Cherry-pick -x | Tracks origin, auditable | Still creates duplicate commits |
| Cherry-pick —no-commit | Review before committing | Extra step, easy to forget to commit |
Implementation Snippets
# Backport a bug fix to release branch
git switch release/v1.2
git cherry-pick -x abc1234 # -x adds origin reference
git push origin release/v1.2
# Cherry-pick a range of commits
git switch feature-partial
git cherry-pick main~5..main~2 # commits between these points
# Cherry-pick and edit message
git cherry-pick --edit def5678
# Cherry-pick without committing (review first)
git cherry-pick --no-commit ghi9012
git diff --cached # review the staged changes
git commit -m "Backport: fix authentication timeout"
# Batch cherry-pick for hotfix distribution
for branch in release/v1.0 release/v1.1 release/v1.2; do
git switch $branch
git cherry-pick -x abc1234
git push origin $branch
done
Observability Checklist
- Logs: Record cherry-pick operations with original commit references
- Metrics: Track cherry-pick frequency (high frequency may indicate branching issues)
- Alerts: Alert on cherry-picks to production branches without review
- Traces: Link cherry-picked commits to original commits via
-xflag - Dashboards: Display backport success rate and conflict frequency
Security & Compliance Considerations
- Cherry-picked commits should reference the original commit for audit trails
- Use
-xflag to automatically append the original commit SHA - Verify that cherry-picked security fixes don’t introduce regressions
- Document cherry-pick operations in release notes
- Ensure cherry-picked commits pass the same CI checks as regular commits
Common Pitfalls / Anti-Patterns
- Cherry-picking without understanding dependencies — commits often depend on earlier work
- Creating duplicate history — cherry-picking merged commits creates confusion about what’s actually in a branch
- Forgetting to test — cherry-picked changes may behave differently in a different context
- Cherry-picking merge commits without
-m— produces unexpected results - Using cherry-pick as a regular workflow — it should be the exception, not the rule
- Losing attribution — always use
-xor--signoffto preserve the original author
Quick Recap Checklist
- Cherry-pick applies individual commits to a different branch
- Use
git cherry-pick <sha>for single commits - Use
-xto track the original commit source - Use
--no-committo review changes before committing - Use
-m 1when cherry-picking merge commits - Resolve conflicts with
git cherry-pick --continue - Abort with
git cherry-pick --abort - Always test cherry-picked changes in their new context
Architecture: How Cherry-Pick Creates New Commits
graph TD
subgraph "Source Branch: feature"
E["commit E"] --> F["commit F (bug fix)\nSHA: abc1234"]
F --> G["commit G"]
end
subgraph "Target Branch: release/v1.0"
D["commit D"] --> NewF["commit F'\nSHA: xyz7890\nSame diff, different SHA\nParent: D instead of E"]
end
F -. "git cherry-pick F" .-> NewF
F -. "Same changes" .-> NewF
classDef commit color:#00fff9
class E,F,G,D,NewF commit
Cherry-pick computes the diff introduced by the source commit, then applies that diff to the target branch and creates a brand new commit with the target branch as its parent. The new commit has a different SHA, different parent, and different commit date (though author info is preserved).
Production Failure: Cherry-Picking Across Diverged Branches
Scenario: A developer cherry-picks a bug fix from main (which uses a new API version) onto release/v1.0 (which still uses the old API). The cherry-pick applies cleanly because the changed lines don’t overlap, but the fix depends on the new API that doesn’t exist in the release branch.
Impact: The code compiles and tests pass in isolation, but the fix silently fails in production because the API call returns unexpected data. The bug appears “fixed” but the underlying issue persists.
Mitigation:
- Always review the full diff before cherry-picking, not just the conflict status
- Check for hidden dependencies — does the commit rely on changes in other commits?
- Run integration tests on the target branch after cherry-picking
- Use
git show <sha>to understand the full context before cherry-picking - Consider manual backporting instead of cherry-pick for significantly diverged branches
# Review the full diff before cherry-picking
git show abc1234
# Check what files the commit touches
git diff-tree --no-commit-id --name-only -r abc1234
# Check if the commit depends on earlier commits
git log --oneline abc1234~5..abc1234
# After cherry-pick, verify the change makes sense in context
git diff HEAD~1 # compare new commit with its parent
Trade-offs: Backporting Hotfixes
| Approach | Best For | Pros | Cons |
|---|---|---|---|
| Cherry-pick | Single, self-contained commits | Fast, precise, preserves attribution with -x | Creates duplicate commits, may miss dependencies |
| Merge | Entire feature branches | Preserves relationships, single source of truth | Brings all changes, may include unwanted work |
| Rebase | Keeping branches current | Clean linear history | Rewrites history, not for shared branches |
| Manual backport | Significantly diverged branches | Full control, can adapt changes to target context | Time-consuming, error-prone, loses attribution |
| Cherry-pick -x | Auditable backports | Tracks origin automatically | Still creates duplicate commits |
Summary Checklist
- Cherry-pick creates a new commit with the same changes but different SHA
- Always review the full diff with
git show <sha>before cherry-picking - Use
-xflag to track the original commit source for audit trails - Check for hidden dependencies — commits often rely on earlier work
- Run integration tests on the target branch after cherry-picking
- Use
--no-committo review changes before committing - Use
-m 1when cherry-picking merge commits - Consider manual backporting for significantly diverged branches
- Cherry-pick should be the exception, not the regular workflow
Interview Questions
git cherry-pick and git merge?git merge integrates all changes from one branch into another, creating a merge commit that records the relationship. git cherry-pick applies specific individual commits to the current branch, creating new commits with different SHAs. Merge preserves history; cherry-pick duplicates it.
-x flag do in git cherry-pick?The -x flag appends a line to the commit message indicating the original commit SHA: (cherry picked from commit abc1234...). This creates an audit trail linking the cherry-picked commit to its source, which is invaluable for tracking where changes originated.
Use the -m flag to specify which parent to diff against: git cherry-pick -m 1 <merge-sha>. -m 1 uses the first parent (the branch you were on when merging), -m 2 uses the second parent (the merged branch). Without -m, Git doesn't know which parent to use as the base.
Cherry-picking creates new commits with different SHAs. If you later merge the original branch, Git doesn't recognize that the changes are already present, leading to duplicate changes or conflicts. For multiple commits, prefer merge or rebase to maintain the relationship between commits.
--no-commit and --edit flags?--no-commit (or -n) applies the changes and stages them but does not create a commit, letting you review or modify before committing manually. --edit (or -e) creates the commit but opens your editor to modify the commit message before saving. Use -n for reviewing changes; use -e for editing the message of an already-created commit.
When conflicts occur, Git marks them in the affected files. Resolve each file manually, then run git add <resolved-file> for each resolved file. Once all conflicts are staged, run git cherry-pick --continue to complete the operation. To abort and return to the pre-cherry-pick state, use git cherry-pick --abort.
The author information is preserved — the original author name, email, and timestamp are retained in the cherry-picked commit. However, the committer timestamp and SHA change because you (or another committer) are creating a new commit on the target branch. Use --signoff if you need to add your own attribution alongside the original author.
git revert instead of git cherry-pick?Use git revert when you need to undo a commit's changes safely without removing it from history. Revert creates a new commit that applies the inverse of the target commit, making it safe for shared branches. Use cherry-pick when you want to apply specific changes to another branch (not undo them), such as backporting a fix. Revert is the safer choice for undoing; cherry-pick is for duplicating.
You'll likely encounter merge conflicts. If the same lines were modified differently in each branch, Git cannot automatically resolve the difference. You must manually edit the conflicting sections, then stage and continue the cherry-pick. Even if there are no conflicts, the resulting code may have logical bugs if the context assumptions differ.
Cherry-picking a single commit does not automatically bring its children. Each commit must be cherry-picked individually. If commit B depends on changes from commit A (its parent), cherry-picking only B will likely cause conflicts or produce incorrect results because B's changes assume A's changes are present. Always review dependencies before cherry-picking.
Tags are references that point to specific commits. Cherry-picking a tag's commit creates a new commit with a different SHA, but the tag still points to the original commit. To "move" a tag, you must delete the old tag and create a new one pointing to the new commit: git tag -d old-tag && git tag old-tag new-sha. Note that this changes the tag's meaning for anyone who already pulled it.
Cherry-picking to a branch creates a new commit on that branch's tip. Cherry-picking to a tag is not directly possible — tags are static references. If you check out a tag (creating a detached HEAD), cherry-picking there creates an orphaned commit not reachable from any branch. You would need to explicitly create a branch from the tag first to preserve the cherry-picked work.
Cherry-pick preserves submodule references as long as the submodule commits exist. When you cherry-pick a commit that changes a submodule pointer, the new commit references the same submodule commit (or the nearest available one if the original is not local). If the submodule commit is missing, Git will report a submodule reference error until the submodule is updated.
git cherry-pick --signoff do that -x does not?--signoff adds a trailer line indicating who performed the cherry-pick: Signed-off-by: Your Name <your@email>. This is used for license compliance (DCO - Developer Certificate of Origin) and shows who applied the change. -x only records the original commit SHA, not the identity of who cherry-picked it. Use both flags together for complete audit trails.
Use git show <sha> to see the diff of the commit you intend to cherry-pick. You can also use git cherry-pick -n <sha> to apply changes without committing, then review the working tree with git diff. Once satisfied, commit manually with git commit. This gives you full control over the resulting commit message and lets you verify the changes.
This happens when the cherry-picked commit depends on context that differs between branches — other commits, configuration files, API versions, or dependent code. The diff applies cleanly, but the change doesn't make sense in the new context. Always review the full diff with git show before cherry-picking, and run integration tests after merging to the target branch.
--allow-empty flag in cherry-pick?By default, cherry-pick skips commits that would produce no changes in the target branch. The --allow-empty flag forces creation of a commit even if the diff is empty. This is useful when the commit message contains important information (like a bug ID or change rationale) that needs to be preserved in the target branch's history.
Use the range syntax with a caret on the start: git cherry-pick abc1234^..def5678 includes both commits. To exclude the first commit, start from the second one directly: git cherry-pick abc1235 def5678 (where abc1235 is the commit after abc1234). Alternatively, use git rebase to reorder and filter commits before cherry-picking.
Stash entries are independent of cherry-pick operations. Cherry-picking does not modify or delete stashes. However, if you have stashed changes and then cherry-pick commits that modify the same files, you may encounter conflicts when you later unstash. It's recommended to resolve all stash entries before performing cherry-picks to avoid confusion.
Cherry-picking multiple commits with git cherry-pick commit1 commit2 commit3 is not atomic by default — if one fails, previous commits in the sequence are already applied. For atomic behavior, use git cherry-pick --abort to restore the original state if any commit fails, or wrap the operation in a transaction script that checks the exit code and aborts if any cherry-pick fails, then retry or report the failure.
Further Reading
Additional Resources
The Git Book’s chapters on branching and rebasing provide the conceptual foundation that makes cherry-pick click. Once you understand how Git tracks history, cherry-pick’s behavior — applying a diff as a new commit — becomes obvious rather than magical. The Atlassian tutorial walks through several scenarios with visual diagrams that help if you’re more spatial than textual.
The Pro Git book is free at git-scm.com/book. Chapters 3.1 through 3.6 cover branching and rebasing. Chapter 3.1, “Branches in a Nutshell,” describes how commits are snapshots and branches are just pointers that move around — once that clicks, cherry-pick stops feeling like magic and starts making sense. Chapter 3.2, “Basic Branching and Merging,” shows exactly when to reach for cherry-pick: you’ve got a fix on one branch but do not want to drag in everything else. Chapter 3.4, “Rebasing,” covers the alternative. After reading these, cherry-pick becomes obvious instead of mysterious.
Atlassian’s Git tutorial on cherry-pick (atlassian.com/git/tutorials/cherry-pick) covers four scenarios: single commit, multiple commits, conflict handling, and cherry-picking all commits from one branch. Each one has before-and-after diagrams of the branch graph, so you can actually see how the structure changes. The conflict resolution section shows what the index looks like when cherry-pick stops mid-operation and what you need to do to continue. That is the part that clears up “stopped at commit X” confusion.
The documentation at git-scm.com/docs/git-cherry-pick lists flags for edge cases. --allow-empty creates a commit even when the diff is empty in the target branch — useful when the change is already there but the commit message is what you need. --allow-empty-message does the same for commits with no message. --keep-redundant-commits goes the other way: it forces a commit even if the diff matches what is already in the target branch. These are rare, but when cherry-pick silently skips your commit and you cannot figure out why, knowing these exist will save you an hour of debugging.
The official git-cherry-pick documentation is worth bookmarking for the flags you won’t use every day: --allow-empty, --allow-empty-message, and --keep-redundant-commits. You’ll need them rarely, but when you do, you’ll be glad you know they exist.
Related Commands
Cherry-pick rarely works in isolation. git log --oneline is usually the first step — finding the SHA you want to apply. git show <sha> before you cherry-pick is not optional if the commit has any complexity; it’s your chance to understand what you’re actually moving. git reflog saves you when a cherry-pick goes sideways and you need to find your way back. git revert is the cousin you’ll reach for when you want to undo rather than duplicate — it creates an inverse commit rather than copying a forward one.
| Command | Use Case |
|---|---|
git log --oneline | Find commit SHAs to cherry-pick |
git show <sha> | Preview commit changes before applying |
git reflog | Recover from mistakes or find dropped commits |
git revert <sha> | Create inverse of a commit (safe alternative to cherry-pick for undoing) |
git stash | Temporarily store changes for later use |
Advanced Topics to Explore
Once cherry-pick is comfortable, these topics extend what you can do with it. git rerere (reuse recorded resolution) remembers how you resolved a conflict and applies that resolution automatically the next time the same conflict appears — useful when you’re repeatedly cherry-picking from the same branch. git bisect combined with cherry-pick lets you reproduce bugs across branches for targeted testing. Interactive rebase, while not a cherry-pick topic, is worth knowing if you want to clean up commit history before moving commits around.
- Cherry-pick vs. revert — when to use inverse commits instead of cherry-picking
- git rerere — reuse recorded resolutions to handle repeated conflicts
- Interactive rebase — clean up commits before cherry-picking to reduce conflicts
- Bisect with cherry-pick — reproduce bugs across branches for testing
Conclusion
Cherry-pick is the surgical tool in Git’s toolkit — use it when you need exactly one change from another branch without merging everything. It’s invaluable for hotfixes, backporting bug fixes, and selective feature porting. Just be mindful that overuse can create confusing duplicate histories across branches.
Category
Related Posts
Master git add: Selective Staging, Patch Mode, and Staging Strategies
Master git add including selective staging, interactive mode, patch mode, and staging strategies for clean atomic commits in version control.
Git Branch Basics: Creating, Switching, Listing, and Deleting Branches
Master the fundamentals of Git branching — creating, switching, listing, and deleting branches. Learn the core commands that enable parallel development workflows.
Rebase vs Merge: When to Use Each in Git
Decision framework for choosing between git rebase and git merge. Understand trade-offs, team conventions, history implications, and production best practices.