From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: Alexander Mills <alexander.d.mills@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: check if one branch contains another branch
Date: Thu, 7 May 2020 23:47:18 +0000 [thread overview]
Message-ID: <20200507234718.GC7234@camp.crustytoothpaste.net> (raw)
In-Reply-To: <CA+KyZp4keGp8j0rzCtr0fEogZqkKwTNLvRBZ2QOUzjStP+V2uA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1890 bytes --]
On 2020-05-07 at 23:28:40, Alexander Mills wrote:
> Thanks will check that out.
>
> This command does not seem to work :(
>
> > git branch --contains branchB
>
> I do this:
>
> git checkout branchB
> git commit --allow-empty -am 'empty commit message'
> git checkout dev
> git branch --contains branchB ==> exit code 0
> git branch --contains $(git rev-parse branchB) ==> exit code 0
>
> this seems like a bug or something. Why wouldn't it exit with 1,
> since it obviously does not contain that commit?
Because that command operates differently. From git-branch(1):
With --contains, shows only the branches that contain the named commit
(in other words, the branches whose tip commits are descendants of the
named commit)…..
git branch --contains branchB prints only branchB, because no other
branch contains it. In other words, this asks to list the branches
which contain the specified commit, and as long as it has done so
successfully (even if that answer is "none of them"), it exits 0. The
current branch has no effect on it because it's listing branches which
match a criterion, not comparing the specified revision to the current
branch.
Note that this is not a porcelain command (that is, it is not intended
for scripting) and need not be especially performant. git merge-base
--is-ancestor is the better way if you want to script things or get a
more performant answer because it does less work, especially if there
are many branches.
> This kinda sucks tbh :(
Certainly it fails to do the thing you wanted to do with it, but since
that isn't what it's documented to do, I don't see that as a particular
problem.
Is the documentation unclear in some way or could it be more helpful?
If so, please tell us so we can improve it.
--
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]
next prev parent reply other threads:[~2020-05-07 23:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-07 22:59 check if one branch contains another branch Alexander Mills
2020-05-07 23:08 ` Junio C Hamano
2020-05-07 23:12 ` Alexander Mills
2020-05-07 23:15 ` Alexander Mills
2020-05-07 23:24 ` brian m. carlson
2020-05-07 23:28 ` Alexander Mills
2020-05-07 23:47 ` brian m. carlson [this message]
2020-05-07 23:31 ` Randall S. Becker
2020-05-07 23:37 ` Alexander Mills
2020-05-07 23:41 ` Junio C Hamano
2020-05-08 1:01 ` Alexander Mills
2020-05-08 12:07 ` Randall S. Becker
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=20200507234718.GC7234@camp.crustytoothpaste.net \
--to=sandals@crustytoothpaste.net \
--cc=alexander.d.mills@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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).