In a prior question someone provided an answer for finding branches that contained an EXACT commit:
How to list branches that contain a given commit
The acce
The following seems to work (but hasn't been tested much). It runs git cherry for each local git branch, and prints the branch name if git cherry doesn't list the commit as missing from the branch.
# USAGE: git-cherry-contains [refs]
# Prints each local branch containing an equivalent commit.
git-cherry-contains() {
local sha; sha=$(git rev-parse --verify "$1") || return 1
local refs; refs=${2:-refs/heads/}
local branch
while IFS= read -r branch; do
if ! git cherry "$branch" "$sha" "$sha^" | grep -qE "^\+ $sha"; then
echo "$branch"
fi
done < <(git for-each-ref --format='%(refname:short)' $refs)
}
See Andrew C's post for a great explanation of how git cherry actually works (using git patch-id).