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

David Gobbi david.gobbi at gmail.com
Fri Oct 8 08:59:57 EDT 2010


On Fri, Oct 8, 2010 at 6:37 AM, David Cole <david.cole at kitware.com> wrote:
> 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
>
>
> Or, you could just use...
>   git branch --contains abcdef12
> ...and git will list the branches that contain the commit with id
> "abcdef12"...
>
> HTH,
> David

Thanks for all the answers.  I think that I asked the wrong question,
though.  What I meant to ask was: after a branch has been merged and
deleted, can it be reconstructed?  I.e. is there a git command to find
all the merge commits, and extract the commits they point to?

  David



More information about the vtk-developers mailing list