* How to find the first commit belonging to any branch
@ 2008-07-22 9:08 Kristian Amlie
2008-07-22 9:27 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Kristian Amlie @ 2008-07-22 9:08 UTC (permalink / raw)
To: git
Hi all!
I have a question about git: I have one commit sha1, and I would like to
know the nearest commit that appears in *any* other branch. The sha1
that I have does not belong to any branch.
The obvious thing to do would be to make a for loop and iterate over
existing branches while calling git merge-base, but I'm wondering if
there's a more clever method.
Regards
Kristian Amlie
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to find the first commit belonging to any branch
2008-07-22 9:08 How to find the first commit belonging to any branch Kristian Amlie
@ 2008-07-22 9:27 ` Junio C Hamano
2008-07-22 11:18 ` Kristian Amlie
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2008-07-22 9:27 UTC (permalink / raw)
To: Kristian Amlie; +Cc: git
Kristian Amlie <kristian.amlie@trolltech.com> writes:
> I have a question about git: I have one commit sha1, and I would like
> to know the nearest commit that appears in *any* other branch. The
> sha1 that I have does not belong to any branch.
>
> The obvious thing to do would be to make a for loop and iterate over
> existing branches while calling git merge-base, but I'm wondering if
> there's a more clever method.
If the $commit does not belong to any branch, then:
$ git rev-list --bounardy $commit^0 --not --branches | sed -ne 's/^-//p'
would give you boundary commits of the above traversal, which says:
Traverse from $commit following the parents, but stop at anything that
is reachable from any breanch.
which means that the ones that are output are the candidates that are on
some branch.
So pipe that to name-rev like this, perhaps (untested)?
$ git rev-list --bounardy $commit^0 --not --branches |
sed -ne 's/^-//p' |
git name-rev --stdin
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: How to find the first commit belonging to any branch
2008-07-22 9:27 ` Junio C Hamano
@ 2008-07-22 11:18 ` Kristian Amlie
0 siblings, 0 replies; 3+ messages in thread
From: Kristian Amlie @ 2008-07-22 11:18 UTC (permalink / raw)
To: git
Junio C Hamano wrote:
> Kristian Amlie <kristian.amlie@trolltech.com> writes:
>
>> I have a question about git: I have one commit sha1, and I would like
>> to know the nearest commit that appears in *any* other branch. The
>> sha1 that I have does not belong to any branch.
>>
>> The obvious thing to do would be to make a for loop and iterate over
>> existing branches while calling git merge-base, but I'm wondering if
>> there's a more clever method.
>
> If the $commit does not belong to any branch, then:
>
> $ git rev-list --bounardy $commit^0 --not --branches | sed -ne 's/^-//p'
>
> would give you boundary commits of the above traversal, which says:
>
> Traverse from $commit following the parents, but stop at anything that
> is reachable from any breanch.
>
> which means that the ones that are output are the candidates that are on
> some branch.
>
> So pipe that to name-rev like this, perhaps (untested)?
>
> $ git rev-list --bounardy $commit^0 --not --branches |
> sed -ne 's/^-//p' |
> git name-rev --stdin
>
>
Thanks! That did the trick!
Kristian
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-07-22 11:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-22 9:08 How to find the first commit belonging to any branch Kristian Amlie
2008-07-22 9:27 ` Junio C Hamano
2008-07-22 11:18 ` Kristian Amlie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).