Git Reference ยท Merging and Rebasing
git cherry command
Reference for git cherry: compare commits by patch content and mark which of your commits are already in upstream (-) and which are not (+), even after cherry-picks.
git cherry compares two lines of history by the content of each commit's patch, not by commit id. It lists the commits that are on your branch but not on the upstream branch, marking each with + (no equivalent change found upstream) or - (an equivalent change is already there).
That makes it the right tool after cherry-picks and rebases, when the same change exists under different commit ids and a plain git log upstream..HEAD would still list it. It answers "which of my commits has the maintainer actually applied?" and "which of these fixes did I forget to backport?".
git cherry -v origin/main # your commits vs. upstream, with subjects git cherry -v main feature # explicit branches
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
git cherry [-v] [<upstream> [<head> [<limit>]]]
| Name | Description |
|---|---|
<upstream> |
The branch to compare against. Default: the configured upstream of the current branch. |
<head> |
The branch whose commits are listed. Default: HEAD. |
<limit> |
Skip commits reachable from this one (and the commits before it). |
-v |
Show the commit subject after each id. |
Output: one line per commit in <head> that is not an ancestor of <upstream>, oldest first: + <id> if no equivalent commit exists in <upstream>, - <id> if there is one.
Errors: fatal: Could not find a tracked remote branch, please specify <upstream> manually when no upstream is configured and none was given.
Usage notes
- Equivalence is by patch id. Git hashes each commit's diff (ignoring line numbers and whitespace at line ends) and compares the hashes. Two commits with the same diff are equal even if their messages, authors and ids differ; a commit edited while being picked is a different patch, as the second example shows.
- Same engine as
rebase. Git rebase andgit log --cherry-pickuse patch ids to skip commits that already exist upstream.git log --left-right --cherry-mark main...topicshows a similar view insidegit log. - A commit that changed during conflict resolution is usually no longer detected, because its diff differs. Treat
+as "probably missing" and check by hand. - Only your side is listed.
git cherrylooks one way: commits in<head>missing from<upstream>. Swap the arguments to see the other direction. - Merge commits are not compared; only non-merge commits appear.
- Related helper.
git cherryis a thin wrapper overgit patch-idandgit rev-list --cherry-mark; the latter works on arbitrary ranges. - Release workflow. Before cutting a release,
git cherry -v release mainshows which fixes frommainhave not been backported torelease. - No changes to the repository. The command only reads.
Related
git cherry-pick,git rebase,git log,git merge-base- Lessons: Cherry-pick, Log and Show