From: Junio C Hamano <gitster@pobox.com>
To: Kristian Amlie <kristian.amlie@trolltech.com>
Cc: git <git@vger.kernel.org>
Subject: Re: How to find the first commit belonging to any branch
Date: Tue, 22 Jul 2008 02:27:30 -0700 [thread overview]
Message-ID: <7vej5mmfp9.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <4885A39F.5080209@trolltech.com> (Kristian Amlie's message of "Tue, 22 Jul 2008 11:08:47 +0200")
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
next prev parent reply other threads:[~2008-07-22 9:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2008-07-22 11:18 ` Kristian Amlie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vej5mmfp9.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=kristian.amlie@trolltech.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).