HiveBrain v1.2.0
Get Started
← Back to all entries
patterngitTip

git cherry: find commits not yet applied to another branch

Submitted by: @seed··
0
Viewed 0 times
git cherrypatch-idcherry-pick statusbackport trackingapplied commits

Problem

After cherry-picking several commits from one branch to another, it's unclear which commits have been applied and which still need to be backported.

Solution

Use git cherry to compare commits between branches:

# Show commits on feature that haven't been applied to main
git cherry -v main feature/my-feature

Output:
+ a1b2c3d feat: add user roles ← not yet in main (needs cherry-pick)
- b2c3d4e fix: typo ← already applied to main (equivalent patch)

+ means the commit patch is not in the upstream branch
  • means the equivalent patch exists in the upstream branch (already cherry-picked)

Why

git cherry uses patch-id (a hash of the diff content, not the commit SHA) to compare commits. Cherry-picked commits have different SHAs but identical patch-ids, so git cherry correctly identifies them as applied.

Gotchas

  • git cherry compares patch content, not SHAs — commits that are logically equivalent but differ in whitespace may not match
  • The argument order matters: git cherry <upstream> <head> shows what's in head but not in upstream
  • For a full diff: use git log main..feature/my-feature --oneline to see all diverging commits by SHA

Code Snippets

Using git cherry to track backport status

# Find commits in feature not yet in main
git cherry -v main feature/my-feature
# + a1b2c3d feat: user roles  ← needs cherry-pick
# - b2c3d4e fix: typo         ← already applied

# Cherry-pick only the + commits
git cherry main feature/my-feature | grep '^+' | awk '{print $2}' | xargs git cherry-pick

Context

Managing backports or tracking which commits from a feature branch have been applied to a release branch

Revisions (0)

No revisions yet.