LinuxCommandLibrary

git-cherry

Find commits not yet up-streamed

TLDR

Show commits (and their messages) with equivalent commits upstream

$ git cherry [[-v|--verbose]]
copy

Specify a different upstream and topic branch
$ git cherry [origin] [topic]
copy

Limit commits to those within a given limit
$ git cherry [origin] [topic] [base]
copy

SYNOPSIS

git cherry [--verbose] <upstream> <head> [--rightmost | --leftmost]

PARAMETERS

--verbose
    Show verbose output with one-line commit messages alongside +/- markers and commit IDs.

<upstream>
    Branch (or commit) to compare against; commits equivalent to those in this are marked '+'.

<head>
    Branch (or commit) whose unique commits are listed.

--rightmost
    Output only the rightmost (newest) qualifying commit in <head>.

--leftmost
    Output only the leftmost (oldest) qualifying commit in <head>.

DESCRIPTION

git cherry is a Git porcelain command used to identify commits present in one branch (head) that are absent from another (upstream). It helps developers check if changes have been integrated, cherry-picked, or remain pending.

It outputs lines starting with '+' for commits in head with an equivalent patch already in upstream (e.g., via cherry-pick or merge), and '-' for truly unique commits. Equivalence is determined by comparing patch-ids, ignoring whitespace and commit metadata.

This is useful in distributed workflows, like verifying if a topic branch's fixes are in the mainline after rebasing or merging. Output is ordered by appearance in head, making it easy to scan recent changes first.

For verbose mode, it appends the commit subject line. Limiting options like --rightmost or --leftmost restrict output to boundary commits, aiding bisect-like debugging.

CAVEATS

Patch-ID equivalence may miss semantically identical changes with minor diffs (e.g., whitespace). Does not traverse merge history deeply; use with git log --no-merges for precision. Requires common ancestor.

EXAMPLE

git cherry origin/master mytopic
Outputs:
- a1b2c3d Fix bug #42
+ e4f5g6h Similar fix (already in master)

git cherry -v upstream develop adds subject lines.

HISTORY

Introduced in Git 1.3.0 (2006-06) by Junio C Hamano to aid integration tracking. Evolved with patch-id improvements; stable since Git 1.7+ with --rightmost/--leftmost added in 1.7.4 (2010).

SEE ALSO

Copied to clipboard