[vtk-developers] Git tool for tracing merged branches?

Olesen, Mark mark.olesen at faurecia.com
Fri Oct 8 03:22:36 EDT 2010


> To my knowledge, there is no way to get what branch a commit was
> created on because that information is not stored.  Commits are
> identified only by their SHA and only record the parent commits from
> which they derive.  A branch is really just a pointer to some commit.
> When the branch moves or goes away, there is no record of it ever
> having pointed to a particular commit.

This is indeed the problem.
The only solution I can think of is brute force:
1. specify which commit you want to trace
2. get a list of all possible branches (or specify some)
3. walk each branch and see if you encounter the specified commit

As pseudo-code:

# define your value
commit=...... 

# check it is a valid commit
info="$(git cat-file -t $commit)"
rc=$?
if [ $rc -ne 0 ]
then
    echo "$info" 1>&2
    exit $rc
elif [ "$info" != commit ]
then
    echo "Not a commit: $info" 1>&2
    exit 1
fi


# use all branches or specify some others
branches=$(git branch -al | sed -e s/^..//)

where=$(
    for branch in $branches
    do
        echo "check branch: $branch" 1>&2
        git rev-list $branch | grep -qe "^$commit"
        [ $? -eq 0 ] && echo $branch
    done
)

echo
echo "commit $commit is in these branches:"
echo $where | tr '\n' ' '
echo



If the commit in question has been cherry-picked to another branch, this
won't help you much though.

/mark



DISCLAIMER:
This electronic transmission (and any attachments thereto) is intended solely for the use of the addressee(s). It may contain confidential or legally privileged information. If you are not the intended recipient of this message, you must delete it immediately and notify the sender. Any unauthorized use or disclosure of this message is strictly prohibited. Faurecia does not guarantee the integrity of this transmission and shall therefore never be liable if the message is altered or falsified nor for any virus, interception or damage to your system.




More information about the vtk-developers mailing list