#!/bin/bash commit=$1 [ "$commit" ] || { echo "$0: [ []]" 1>&2 exit 1 } commit=$(git rev-parse --verify "$commit") [ "$commit" ] || exit 1 top=$2 [ "$top" ] || top=HEAD linus=$3 [ "$linus" ] || linus=origin/master base=$(git merge-base "$linus" "$top") git log --first-parent --reverse --pretty='format:%H %P' "$base".."$top" | while read m p1 p2 do [ "$p1" = "$commit" ] && { echo "Directly committed" break } [ "$p2" ] || continue git rev-list $base..$p2 | grep -q "$commit" || continue branch=$(git show $m | sed -n "s/[ ]*Merge .*'\([^']*\)'\( of \([^ ]*\).*\)*$/\1|\3/p") tree=${branch##*|} branch=${branch%%|*} [ "$tree" ] || { tree=${branch%%/*} [ "$tree" = "quilt" ] && tree=${branch##*/} echo "$tree" break } echo "$tree#$branch" break done exit 0