0
0
Gitdevops~10 mins

git cherry-pick a single commit - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - git cherry-pick a single commit
Start on target branch
Identify commit hash to pick
Run git cherry-pick <commit-hash>
Git applies changes from commit
Check for conflicts?
YesResolve conflicts
Continue cherry-pick
Commit applied on target branch
Done
The flow shows starting on the target branch, picking a commit by its hash, applying it, resolving conflicts if any, and finishing with the commit added.
Execution Sample
Git
git checkout feature-branch
# switch to target branch

git cherry-pick a1b2c3d4
# apply commit a1b2c3d4 changes

# If conflicts, resolve and run:
git cherry-pick --continue
This sequence switches to the target branch and applies a single commit from another branch by its hash.
Process Table
StepActionCommandResultNotes
1Switch to target branchgit checkout feature-branchSwitched to branch 'feature-branch'Ready to apply commit here
2Run cherry-pickgit cherry-pick a1b2c3d4Git applies commit changesIf no conflicts, commit added
3Check for conflictsAutomaticNo conflicts detectedCherry-pick successful
4Cherry-pick completeAutomaticCommit a1b2c3d4 added to feature-branchDone applying commit
💡 Cherry-pick ends after commit is applied or conflicts resolved and continued
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
HEAD branchmainfeature-branchfeature-branchfeature-branchfeature-branch
Commit historymain branch commitsfeature-branch commitsfeature-branch + a1b2c3d4 commitfeature-branch + a1b2c3d4 commitfeature-branch + a1b2c3d4 commit
Conflict statenonenonenonenonenone
Key Moments - 3 Insights
What happens if you run cherry-pick on the wrong branch?
The commit will be applied to the current branch HEAD points to, which may cause unwanted changes. See execution_table step 1 where switching branch is important.
What if there are conflicts during cherry-pick?
Git pauses and asks you to resolve conflicts manually, then you run 'git cherry-pick --continue' to finish. This is shown in the concept_flow with the conflict branch.
Does cherry-pick change the original commit hash?
No, but the new commit on the target branch gets a new hash because it is a new commit object. The original commit remains unchanged.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what branch is HEAD on after step 1?
Aa1b2c3d4
Bfeature-branch
Cmain
Ddetached HEAD
💡 Hint
Check the 'Result' column in step 1 of execution_table
At which step does git apply the commit changes?
AStep 2
BStep 1
CStep 3
DStep 4
💡 Hint
Look at the 'Action' and 'Result' columns in execution_table for when changes are applied
If conflicts occur, what command should you run after resolving them?
Agit commit --amend
Bgit cherry-pick --abort
Cgit cherry-pick --continue
Dgit merge --continue
💡 Hint
Refer to the execution_sample code comments about conflict resolution
Concept Snapshot
git cherry-pick <commit-hash>
- Applies a single commit from another branch onto current branch
- Must be on target branch before running
- If conflicts, resolve then run 'git cherry-pick --continue'
- Creates a new commit with same changes but new hash
- Useful to selectively copy changes without merging
Full Transcript
To cherry-pick a single commit, first switch to the branch where you want the commit applied. Then run 'git cherry-pick' with the commit hash. Git applies the changes from that commit onto your current branch. If there are conflicts, git will pause and ask you to resolve them. After fixing conflicts, run 'git cherry-pick --continue' to finish. The cherry-picked commit is added as a new commit on your branch with a new hash. This lets you copy specific changes without merging entire branches.