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

Re: Git *accepts* a branch name, it can't identity in the future?

From
Jeff King <peff@peff.net>
Date
Aug 20, 2017, 08:33 UTC
Message-ID
<20170820083347.mi3bmczkpvy6qwys@sigill.intra.peff.net>
In-Reply-To
<1503215489.5824.4.camel@gmail.com>
On Sun, Aug 20, 2017 at 01:21:29PM +0530, Kaartic Sivaraam wrote:
Show 13 quoted lines
> I made a small assumption in the script which turned out to be false. I
> thought the unicode prefixes I used corresponded to only two bytes.
> This lead to the issue. The unicode character '✓' corresponds to three
> characters and as a result instead of removing it, my script replaced
> it with the unknown character '�'. So, the branch named '✓doc-fix'
> became 'done/�doc-fix'. Here's the issue. I couldn't use 
> 
>     $ git branch -m done/�doc-fix done/dic-fix 
> 
> to rename the branch. Nor could I refer to it in anyway. Git simply
> says,
> 
>     error: pathspec 'done/�doc-fix' did not match any file(s) known to git.
What does "git for-each-ref" say about which branches you _do_ have?
Also, what platform are you on?

I'm wondering specifically if you have a filesystem (like HFS+ on MacOS) that silently rewrites invalid unicode in filenames we create. That would mean your branches are still there, but probably with some funny filename like "done/%xxdoc-fix". Git wouldn't know that name because the filesystem rewriting happened behinds its back (though I'd think that a further open() call would find the same file, so maybe this is barking up the wrong tree).

Another line of thinking: are you sure the � you are writing on the command line is identical to the one generated by the corruption (and if you cut and paste, is perhaps a generic glyph placed in the buffer by your terminal to replace an invalid codepoint, rather than the actual bytes)?

Show 8 quoted lines
> I just wanted to know why git accepted a branch name which it can't
> identify later?
> 
> If it had rejected that name in the first place it would have been
> better. In case you would like to know how I got that weird name,
> here's a way to get that
> 
>     $ echo '✓doc-fix' | cut -c3-100
  [a few defines to make it easy to prod git]
  $ check=$(printf '\342\234\223')
  $ broken=$(printf '\223')
  [this is your starting state, a branch with the unicode name]
  $ git branch ${check}doc-fix
  [you didn't say how your script works, so let's use git to rename]
  $ git branch -m ${check}doc-fix ${broken}doc-fix
  [my terminal doesn't show the unknown-character glyph, but we
   can see the funny character with "cat -A"]:
  $ git for-each-ref --format='%(refname)' | cat -A
  refs/heads/master$
  refs/heads/M-^Sdoc-fix$
  [and we can rename it using that knowledge]
  $ git branch ${broken}doc-fix doc-fix
-Peff
Previous: Kaartic SivaraamNext: Kaartic Sivaraam
Message 4 of 5 in “Git *accepts* a branch name, it can't identity in the future?”
  1. Kaartic SivaraamAug 20, 2017
  2. Johannes SixtAug 20, 2017
  3. Kaartic SivaraamAug 20, 2017
  4. Jeff KingAug 20, 2017
  5. Kaartic SivaraamAug 20, 2017

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.