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

David Cole david.cole at kitware.com
Fri Oct 8 08:37:38 EDT 2010


On Fri, Oct 8, 2010 at 3:22 AM, Olesen, Mark <mark.olesen at faurecia.com>wrote:

> > 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.
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>

Or, you could just use...

  git branch --contains abcdef12

...and git will list the branches that contain the commit with id
"abcdef12"...


HTH,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20101008/122e8c20/attachment.html>


More information about the vtk-developers mailing list