Re: check if one branch contains another branch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux