Cherry-picking commits
Copy a single commit onto another branch with git cherry-pick, see why the copy gets a new ID, and handle conflicts, ranges, merge commits and duplicates.
Creating and switching branchesReading history with log and diff
Cherry-picking commits
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- git cherry-pick <commit> applies the changes of one commit onto your current branch as a new commit.
- The copy has a different ID from the original, since its parent or committer date differs, but it keeps the author, author date and message.
- Add -x to record the original commit ID in the message, and -n to apply the changes without committing.
- A conflict pauses the cherry-pick like a merge does. Resolve and run --continue, or use --abort or --skip.
- Cherry-picking a commit and later merging its branch is allowed but leaves the change in history twice, so use it sparingly.
One commit, not the whole branch
Merging brings everything on a branch. Sometimes you want one thing. In tinynotes, I was working on a dates branch, three commits deep. The first commit, Trim whitespace from new notes, is a small bug fix that has nothing to do with dates, and main needs it today. The rest of the branch isn’t ready.
git cherry-pick takes the changes made by one commit and applies them as a new commit on the branch you’re on. You pick the cherry and leave the tree.
Doing it
$ git log --oneline --graph --all -5
* 839be17 Start the dates work
* e7574e6 Plan note timestamps
* 4a07fc5 Trim whitespace from new notes
* 3702e9b Merge branch 'fix-count'
From main, name the commit:
$ git cherry-pick 4a07fc5
[main 6be578a] Trim whitespace from new notes
Date: Wed Feb 11 10:00:00 2026 +0000
1 file changed, 1 insertion(+), 1 deletion(-)
The graph now shows two commits with the same message on different branches:
* 839be17 Start the dates work
* e7574e6 Plan note timestamps
* 4a07fc5 Trim whitespace from new notes
| * 6be578a Trim whitespace from new notes
|/
* 3702e9b Merge branch 'fix-count'
Why the copy has a new ID
4a07fc5 and 6be578a have the same change and the same message, and the original author and author date (note the Date: Wed Feb 11 line). Their IDs still differ, because a commit’s ID is a hash of its parent, its tree, its author and committer fields and its message. In this example both commits sit on 3702e9b, so the parent is the same and what differs is the committer date, which I had set to a later day. In everyday use the picked commit also lands on a different parent than the original, which changes the ID again. Either way, a cherry-pick makes a new commit and never moves the old one. The original stays on its branch.
Recording where it came from
Add -x and Git appends a line to the message:
$ git cherry-pick -x 4a07fc5
$ git log -1
Trim whitespace from new notes
(cherry picked from commit 4a07fc5dc246a86b6ee2bd3263516b53aa3d6029)
Useful on release branches, where someone later asks “is this fix the same as that one?”. Use -n (--no-commit) to apply the changes to your working directory and staging area without committing, which lets you adjust or combine several picks into one commit. After git cherry-pick -n 4a07fc5, git status -s showed M notes.py, staged and ready.
What happens to the duplicate later
When dates is finished and merged into main, the fix is in both histories. I tried it:
$ git merge dates -m "Merge branch 'dates'"
Merge made by the 'ort' strategy.
DATES.txt | 1 +
README.md | 4 ++++
2 files changed, 5 insertions(+)
create mode 100644 DATES.txt
No conflict: Git saw that the whitespace change was already present and did nothing for it. But the log now lists “Trim whitespace from new notes” twice, once on each side of the merge:
* b6e0c16 Merge branch 'dates'
|\
| * 839be17 Start the dates work
| * e7574e6 Plan note timestamps
| * 4a07fc5 Trim whitespace from new notes
* | 71707ad Trim whitespace from new notes
|/
Harmless for one commit. It gets confusing if you cherry-pick often between long-lived branches, and every duplicate is a place where two histories have drifted. That’s why many teams reserve cherry-pick for carrying fixes to release branches, and reach for merge or rebase otherwise.
Conflicts and escape hatches
A cherry-pick applies a patch, so it can conflict. I changed the same line on main first:
$ git cherry-pick 4a07fc5
Auto-merging notes.py
CONFLICT (content): Merge conflict in notes.py
error: could not apply 4a07fc5... Trim whitespace from new notes
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
It’s the same process as a merge or rebase conflict: edit, git add, then --continue. --abort takes you back, which I ran and got a clean ## main, and --skip drops this one commit.
You can also pick a range: git cherry-pick dates~2..dates replays the last two commits of dates. The range excludes its start, so dates~2 itself is not included. In my run it applied both, ending with [main e2c2761] Start the dates work.
If the change you pick is already present, Git has nothing to commit. I picked HEAD onto itself and got “The previous cherry-pick is now empty, possibly due to conflict resolution”, with git cherry-pick --skip offered as the way out. You will see the same message when you pick a commit whose change arrived some other way.
Cherry-picking a merge commit
$ git cherry-pick 3702e9b
error: commit 3702e9b8355815a62b0b7036cae7422ea6811db9 is a merge but no -m option was given.
fatal: cherry-pick failed
A merge commit has two parents, so “the changes in this commit” is ambiguous: changes relative to which parent? -m 1 means the first parent, normally the branch you merged into. It’s rare. Most cherry-picks are ordinary commits.
What the video covers
tapaScript’s “Git Cherry-Pick Will Finally Make Sense After This” is about fifteen minutes and was published around mid-2026. I had no transcript, so this comes from the title only, which says it explains cherry-pick. It is the longest pick in this group, so treat the length as a sign it may cover several scenarios. The channel is English-language. Philomatics’ “Never* use git cherry-pick” is an opinionated counterpoint on when to avoid it, and Ihatetomatoes has a short demonstration.
Where this fits
That finishes branching and merging. You can create lines of history, join them in two ways, set aside unfinished edits and lift single commits across. The next group takes branches off your machine: remotes, clone, fetch and push.
Check yourself
Why does the cherry-picked commit have a different ID from the original?
A commit's ID is a hash of its parent, tree, author, committer and message. The copy has a different parent or committer date, so its hash differs even with identical changes and message.
When is cherry-pick a better tool than merge?
When you want one specific commit, such as a bug fix, without bringing along the rest of the branch it was made on.
What does git cherry-pick -x add, and why is it useful?
A line '(cherry picked from commit <id>)' in the message. It lets someone later trace the copy back to the original.
You cherry-pick a merge commit and Git errors out. What is missing?
A merge commit has two parents, so Git needs -m to say which parent to diff against. For an ordinary merge into main, -m 1 chooses the mainline.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.