Cherry Pick
Cherry-pick applies the changes from specific commits onto your current branch, without merging entire branches.
What is Cherry Pick?
Cherry-pick copies a commit from one branch and applies it to another. Unlike merge, it doesn't bring the entire branch history - just the specific commit(s) you select.
Before cherry-pick:
main: A---B---C
\
feature: D---E---F
After cherry-picking E to main:
main: A---B---C---E'
\
feature: D---E---FKey points:
- Creates a new commit (E') with the same changes but different hash
- Only applies selected commit(s), not the whole branch
- Original commit remains unchanged on its branch
- Useful for selective integration
When to Use Cherry Pick
Hotfix to Multiple Branches
A bug fix on develop needs to go to main immediately:
- Fix the bug on
develop - Cherry-pick the fix commit to
main - Both branches have the fix
Undo a Specific Feature
Need to include one feature from a branch but not others:
- Identify the commit(s) for that feature
- Cherry-pick only those commits
- Other changes stay on the original branch
Recover Lost Work
Accidentally reset or deleted a branch:
- Find the commit in reflog
- Cherry-pick it to recover the changes
Backport to Release Branch
A feature on main should also go to release-1.0:
- Cherry-pick the feature commits to
release-1.0 - Both versions have the feature
Cherry Pick Use Cases
| Scenario | Action |
|---|---|
| Hotfix needed on multiple branches | Cherry-pick fix to each branch |
| One commit from feature branch | Cherry-pick just that commit |
| Recover from accidental reset | Find in reflog, cherry-pick |
| Backport feature to old release | Cherry-pick to release branch |
| Wrong branch, already committed | Cherry-pick to correct branch, reset original |
Cherry Picking in Axis
Single Commit
- Navigate to History view
- Find the commit you want to cherry-pick
- Right-click the commit
- Select Cherry Pick
- Choose options (see below)
- Click Cherry Pick
Multiple Commits
- Select multiple commits in history (
Ctrl/Cmd + click) - Right-click the selection
- Select Cherry Pick
- Commits are applied in chronological order
Order Matters
When cherry-picking multiple commits, they're applied in order. If commits depend on each other, select them in the correct sequence.
Cherry Pick Options
| Option | Description |
|---|---|
| Create commit | Immediately create a new commit (default) |
| Stage changes only | Apply changes but don't commit (--no-commit) |
Stage Changes Only
Use this when you want to:
- Combine multiple cherry-picks into one commit
- Modify the changes before committing
- Add additional changes with the cherry-picked content
- Start Cherry Pick
- Select Stage changes only option
- Changes are staged but not committed
Handling Conflicts
If the cherry-picked changes conflict with your current branch:
- Conflicting files are shown in staging area
- Open the conflict resolver
- For each conflict:
- Accept Current - Keep your branch's version
- Accept Incoming - Take the cherry-picked version
- Accept Both - Include both changes
- Edit manually for custom resolution
- Mark conflicts as resolved
- Continue or commit the cherry-pick
During Multi-Commit Cherry Pick
When cherry-picking multiple commits:
- Conflict may occur at any commit
- Resolve conflicts for that commit
- Click Continue to proceed to next commit
- Repeat until all commits are applied
Abort Cherry Pick
If cherry-pick goes wrong:
Click Abort to cancel Working directory returns to previous state No commits are created
Skip a Commit
During multi-commit cherry-pick, if one commit can't be applied:
Click Skip to skip that commit Continue with remaining commits
Continue Cherry Pick
After resolving conflicts:
- Resolve conflicts in the staging area
- Click Continue to proceed
Best Practices
Don't Cherry Pick Public Commits
If others are working on the original branch, cherry-picking creates duplicate commits with different hashes. This can cause confusion when branches are eventually merged.
Keep Track of Cherry Picks
Note which commits were cherry-picked and where. Without tracking, the same changes might be merged again later, causing conflicts.
Prefer Merge When Possible
Cherry-pick is for exceptional cases. For regular integration:
- Merge - When you want all changes from a branch
- Cherry-pick - When you need only specific commits
Test After Cherry Pick
The commit worked in its original context. Test that it also works in the new context, especially if:
- Code has diverged between branches
- Dependencies might differ
- Configuration varies between branches
Cherry Pick vs Other Operations
| Operation | Use Case |
|---|---|
| Merge | Integrate entire branch |
| Rebase | Move commits to new base, rewrite history |
| Cherry Pick | Copy specific commits to another branch |
| Revert | Undo a commit by creating inverse changes |
Common Issues
"Nothing to Commit"
The changes from the cherry-picked commit already exist in your branch. This can happen if:
- The commit was already merged another way
- Changes were manually duplicated
Repeated Conflicts on Merge
If you cherry-pick and later merge the same branch, Git may show conflicts for already-applied changes. Options:
- Resolve conflicts by accepting current changes
- Use
git merge -X oursto prefer your version - Consider if cherry-pick was the right choice
Lost Original Context
Cherry-picked commits lose their original branch context. The commit message might reference things that don't make sense in the new location. Consider updating the message.
