On Fri, Oct 8, 2010 at 3:22 AM, Olesen, Mark <span dir="ltr"><<a href="mailto:mark.olesen@faurecia.com">mark.olesen@faurecia.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">> To my knowledge, there is no way to get what branch a commit was<br>
> created on because that information is not stored.  Commits are<br>
> identified only by their SHA and only record the parent commits from<br>
> which they derive.  A branch is really just a pointer to some commit.<br>
> When the branch moves or goes away, there is no record of it ever<br>
> having pointed to a particular commit.<br>
<br>
</div>This is indeed the problem.<br>
The only solution I can think of is brute force:<br>
1. specify which commit you want to trace<br>
2. get a list of all possible branches (or specify some)<br>
3. walk each branch and see if you encounter the specified commit<br>
<br>
As pseudo-code:<br>
<br>
# define your value<br>
commit=......<br>
<br>
# check it is a valid commit<br>
info="$(git cat-file -t $commit)"<br>
rc=$?<br>
if [ $rc -ne 0 ]<br>
then<br>
    echo "$info" 1>&2<br>
    exit $rc<br>
elif [ "$info" != commit ]<br>
then<br>
    echo "Not a commit: $info" 1>&2<br>
    exit 1<br>
fi<br>
<br>
<br>
# use all branches or specify some others<br>
branches=$(git branch -al | sed -e s/^..//)<br>
<br>
where=$(<br>
    for branch in $branches<br>
    do<br>
        echo "check branch: $branch" 1>&2<br>
        git rev-list $branch | grep -qe "^$commit"<br>
        [ $? -eq 0 ] && echo $branch<br>
    done<br>
)<br>
<br>
echo<br>
echo "commit $commit is in these branches:"<br>
echo $where | tr '\n' ' '<br>
echo<br>
<br>
<br>
<br>
If the commit in question has been cherry-picked to another branch, this<br>
won't help you much though.<br>
<br>
/mark<br>
<br>
<br>
<br>
DISCLAIMER:<br>
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.<br>

<div><div></div><div class="h5"><br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtk-developers" target="_blank">http://www.vtk.org/mailman/listinfo/vtk-developers</a><br>
<br>
</div></div></blockquote></div><br><div><br></div><div>Or, you could just use...</div><div><br></div><div>  git branch --contains abcdef12</div><div><br></div><div>...and git will list the branches that contain the commit with id "abcdef12"...</div>
<div><br></div><div><br></div><div>HTH,</div><div>David</div><div><br></div>