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

Re: howto handle name clashes

From
Jeff King <peff@peff.net>
Date
Mar 23, 2012, 18:29 UTC
Message-ID
<20120323182941.GA14236@sigill.intra.peff.net>
In-Reply-To
<4F6CB649.8080006@tu-clausthal.de>
On Fri, Mar 23, 2012 at 06:43:37PM +0100, Sven Strickroth wrote:
> Really problematic is checkout:
> "git checkout heads/foo" creates a detached HEAD (is this intended).
> However, "git checkout heads/foo -B foo" can be used.

Checkout is unlike regular ref lookup in that it prefers branches to other forms (because it is fundamentally a branch operation). So "git checkout foo" should always choose "refs/heads/foo". We do still seem to give the ambiguity warning, though, which seems like overkill.

I think that generally people would want to get rid of ambiguous refs as soon as they notice them, as they are a recipe for disaster. So the warning being annoying has not been considered a huge problem.

> Is there a git command to find out if a name is ambiguous?
> "git rev-parse foo" outputs "warning: refname 'test' is ambiguous.", but
> the return code is zero.
I think you could do:
  case "$(git show-ref --tags --heads $name | wc -l)" in
  0) echo "$name does not exist" ;;
  1) echo "$name is unambiguous" ;;
  *) echo "$name is ambiguous" ;;
  esac
You could also get a list of all ambiguous refs like this:
  git for-each-ref --format='%(refname:short)' refs/heads refs/tags |
  egrep '^(heads|tags)'

The ":short" modifier will shorten names unambiguously, so it ends up leaving the "heads" and "tags" in for ambiguous names.

-Peff
Previous: Sven StrickrothNext: Sven Strickroth
Message 4 of 6 in “howto handle name clashes”
  1. Sven StrickrothMar 23, 2012
  2. Jeff KingMar 23, 2012
  3. Sven StrickrothMar 23, 2012
  4. Jeff KingMar 23, 2012
  5. Sven StrickrothMar 24, 2012
  6. Junio C HamanoMar 23, 2012

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.