Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does the git cherry-pick command do?
It applies the changes introduced by a specific commit from one branch onto the current branch.
Click to reveal answer
beginner
How do you cherry-pick a single commit with hash abc123?
Use the command git cherry-pick abc123 while on the target branch.
Click to reveal answer
intermediate
What should you do if a conflict occurs during git cherry-pick?
Manually resolve the conflicts, then run git cherry-pick --continue to finish.
Click to reveal answer
intermediate
Can git cherry-pick be used to apply multiple commits at once?
Yes, by specifying a range of commits or multiple commit hashes, but for a single commit, just use its hash.
Click to reveal answer
advanced
What happens if you cherry-pick a commit that is already in the current branch?
Git typically aborts because it would result in an empty commit (changes already present), unless --allow-empty is used to create a duplicate with a new hash, which can cause confusion.
Click to reveal answer
What is the purpose of git cherry-pick?
ATo apply a specific commit from another branch to the current branch
BTo delete a commit from the history
CTo merge two branches automatically
DTo create a new branch
✗ Incorrect
git cherry-pick copies changes from a specific commit to your current branch.
Which command applies commit abc123 to your current branch?
Agit merge abc123
Bgit cherry-pick abc123
Cgit checkout abc123
Dgit revert abc123
✗ Incorrect
git cherry-pick abc123 applies that commit's changes to your branch.
If a conflict happens during cherry-pick, what is the next step?
AResolve conflicts manually then run <code>git cherry-pick --continue</code>
BIgnore and continue
CAbort the cherry-pick with <code>git cherry-pick --abort</code>
DDelete the branch
✗ Incorrect
You must fix conflicts and then continue the cherry-pick process.
Can git cherry-pick create duplicate commits?
ANo, it prevents duplicates
BOnly on merge commits
CYes, it creates a new commit with a new hash
DOnly if you use <code>--force</code>
✗ Incorrect
Cherry-pick creates a new commit with a new hash. If the changes already exist, it aborts (empty commit) unless --allow-empty is used.
Which command aborts a cherry-pick in progress?
Agit revert
Bgit reset --hard
Cgit merge --abort
Dgit cherry-pick --abort
✗ Incorrect
git cherry-pick --abort stops the cherry-pick and resets to the previous state.
Explain how to cherry-pick a single commit from another branch and what to do if conflicts occur.
Think about the steps from switching branches to finishing the cherry-pick.
You got /4 concepts.
Describe the risks or issues that can happen when cherry-picking commits.
Consider what happens if the same changes exist or conflicts arise.
You got /3 concepts.
Practice
(1/5)
1. What does the git cherry-pick command do?
easy
A. Creates a new branch from the current commit
B. Deletes a commit from the current branch
C. Merges two branches completely
D. Copies a specific commit from another branch to the current branch
Solution
Step 1: Understand the purpose of git cherry-pick
The command is used to copy a single commit from one branch to another without merging all changes.
Step 2: Compare with other git commands
Unlike merge, cherry-pick applies only one commit, not the entire branch history.
Final Answer:
Copies a specific commit from another branch to the current branch -> Option D
Quick Check:
git cherry-pick = copy single commit [OK]
Hint: Cherry-pick copies one commit, not whole branch [OK]
Common Mistakes:
Confusing cherry-pick with merge
Thinking it deletes commits
Assuming it creates branches
2. Which of the following is the correct syntax to cherry-pick a commit with hash abc123?
easy
A. git cherry-pick abc123
B. git cherry-pick -m abc123
C. git cherry-pick --commit abc123
D. git cherry-pick commit abc123
Solution
Step 1: Recall the basic cherry-pick syntax
The command is git cherry-pick <commit-hash> to apply a single commit.
Step 2: Check the options given
Only git cherry-pick abc123 matches the correct syntax without extra or incorrect flags.
Final Answer:
git cherry-pick abc123 -> Option A
Quick Check:
Correct syntax = git cherry-pick commit_hash [OK]
Hint: Use git cherry-pick followed by commit hash [OK]
Common Mistakes:
Adding unnecessary flags
Using incorrect keywords like 'commit'
Confusing with merge options
3. Given the following commands run on branch main:
git checkout main
git cherry-pick 1a2b3c4
What will happen after these commands?
medium
A. The commit with hash 1a2b3c4 is applied to main branch
B. A new branch named 1a2b3c4 is created
C. The main branch is reset to commit 1a2b3c4
D. The commit 1a2b3c4 is deleted from the repository
Solution
Step 1: Understand the effect of git cherry-pick
Running git cherry-pick 1a2b3c4 applies that commit's changes onto the current branch, here main.
Step 2: Analyze other options
No new branch is created, no reset happens, and commits are not deleted by cherry-pick.
Final Answer:
The commit with hash 1a2b3c4 is applied to main branch -> Option A
Quick Check:
Cherry-pick applies commit to current branch [OK]
Hint: Cherry-pick applies commit changes to current branch [OK]
Common Mistakes:
Thinking it creates branches
Confusing cherry-pick with reset
Assuming it deletes commits
4. You run git cherry-pick abcdef but get a conflict error. What should you do next?
medium
A. Abort the cherry-pick with git cherry-pick --abort and try again
B. Manually resolve the conflicts, then run git cherry-pick --continue
C. Delete the conflicting files and commit
D. Run git reset --hard to fix the conflict
Solution
Step 1: Understand conflict during cherry-pick
Conflicts mean git cannot automatically apply changes; manual resolution is needed.
Step 2: Resolve conflicts and continue
After fixing conflicts in files, run git cherry-pick --continue to finish applying the commit.
Final Answer:
Manually resolve the conflicts, then run git cherry-pick --continue -> Option B
Hint: Fix conflicts, then run git cherry-pick --continue [OK]
Common Mistakes:
Aborting without trying to fix
Deleting files instead of resolving
Using reset which discards changes
5. You want to apply a commit from branch feature to main without merging all changes. The commit hash is f1e2d3c. Which sequence of commands correctly does this?
hard
A. git checkout main
git merge f1e2d3c
B. git checkout feature
git cherry-pick f1e2d3c
git checkout main
C. git checkout main
git cherry-pick f1e2d3c
D. git checkout main
git rebase feature
Solution
Step 1: Switch to the target branch
You must be on main to apply the commit there.
Step 2: Cherry-pick the specific commit
Run git cherry-pick f1e2d3c to copy that commit from feature branch.
Step 3: Analyze other options
Switching to feature, cherry-picking there, then switching back to main does not apply the commit to main, as cherry-pick affects the current branch. Merge and rebase apply entire branches, not a single commit.
Final Answer:
git checkout main
git cherry-pick f1e2d3c -> Option C
Quick Check:
Checkout target branch + cherry-pick commit [OK]
Hint: Checkout target branch first, then cherry-pick commit [OK]