git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Bryan Turner <bturner@atlassian.com>
Cc: wuzhouhui <wuzhouhui14@mails.ucas.ac.cn>,
	Git Users <git@vger.kernel.org>
Subject: Re: How to determine a branch whether has a specified commit
Date: Wed, 18 Dec 2019 23:50:07 -0500	[thread overview]
Message-ID: <20191219045007.GA89333@coredump.intra.peff.net> (raw)
In-Reply-To: <CAGyf7-GK4SJ8oqJ-n1gCdNOq0Dwsxy4V7Eep7qXTsd51pVz7rA@mail.gmail.com>

On Wed, Dec 18, 2019 at 07:09:36PM -0800, Bryan Turner wrote:

> > I think
> >     git branch --contains <commit> | grep <branch name>
> 
> "Combine" the two commands: git branch --contains <commit> <branch
> name>. That will either output the branch's name, if it contains the
> commit, or nothing if it doesn't.

Or "git for-each-ref --contains <commit> refs/heads/<branch>" if you're
scripting.

> A different approach would be something like: git rev-list --count
> <commit> ^<branch name>. If that returns a count of 0, it means the
> commit is reachable from the branch. Otherwise, it'll output some
> positive count indicating how many commits (including the specific
> commit you asked about) are not reachable from the branch. (I suspect
> you don't really need the count, so you could also use "-1" instead of
> "--count".)

That works, but is not quite as careful as some other techniques with
respect to looking past commits with clock skew. A more careful way is
to check that "git merge-base <commit> <branch>" is equal to <commit>.

That clock-skew thing will eventually go away once we start using
generation numbers consistently (but I don't think we do yet in
limit_list(), which handles the "^" part of the traversal).

-Peff

      reply	other threads:[~2019-12-19  4:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-19  2:35 How to determine a branch whether has a specified commit wuzhouhui
2019-12-19  3:09 ` Bryan Turner
2019-12-19  4:50   ` Jeff King [this message]

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=20191219045007.GA89333@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=bturner@atlassian.com \
    --cc=git@vger.kernel.org \
    --cc=wuzhouhui14@mails.ucas.ac.cn \
    /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).