git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 0/2] improve "git branch --contains=<commit> <pattern>"

From
Jeff King <peff@peff.net>
Date
Jan 31, 2013, 06:43 UTC
Message-ID
<20130131064357.GA24660@sigill.intra.peff.net>
In-Reply-To
<679787987.uZRbjA7AMj@al>
On Wed, Jan 30, 2013 at 07:57:03PM +0100, Peter Wu wrote:
Show 12 quoted lines
> Hi,
> 
> I was trying to check whether a certain branch contained a commit and ran:
> 
>      git branch --contains ddc150f7a33ae0c9cb16eaac3641abc00f56316f master
> 
> This resulted in:
> 
>     fatal: A branch named 'master' already exists.
> When "name" does not exist, this command creates a branch. I expect this 
> command to search the mentioned branch, not trying to create it. The manual 
> page of git-branch(1) does not mention such special behavior either.

Yeah, it's sort-of a bug. It is a syntactic ambiguity that an argument to git-branch could be a listing pattern or a new branch name. When using a listing pattern, you need to explicitly specify that you want list mode with `--list`. This is documented in git-branch under --list, but it should be more prominent, in the section that covers the various invocation modes. The first patch below fixes that.

That being said, we could be much more helpful. It seems like --contains should imply listing mode, since it is nonsensical in other modes. The second patch below adjusts that, and makes the command above do what you expect.

  [1/2]: docs: clarify git-branch --list behavior
  [2/2]: branch: let branch filters imply --list
-Peff
Previous: Peter WuNext: Jeff King
Message 2 of 11 in “[BUG] `git branch --contains ID name` creates branch "name"”
  1. Peter WuJan 30, 2013
  2. 0/2 improve "git branch --contains=<commit> <pattern>"Jeff King, Jan 31, 2013
  3. 1/2 docs: clarify git-branch --list behaviorJeff King, Jan 31, 2013
  4. Eric SunshineFeb 1, 2013
  5. Junio C HamanoFeb 1, 2013
  6. Jeff KingFeb 1, 2013
  7. Junio C HamanoFeb 1, 2013
  8. 2/2 branch: let branch filters imply --listJeff King, Jan 31, 2013
  9. Peter WuJan 31, 2013
  10. Junio C HamanoJan 31, 2013
  11. Junio C HamanoJan 31, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.