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
Johannes Sixt <j6t@kdbg.org>
Date
Aug 20, 2017, 08:20 UTC
Message-ID
<829ac9ed-857d-84bf-2374-6a36b1d0aff1@kdbg.org>
In-Reply-To
<1503215489.5824.4.camel@gmail.com>
Am 20.08.2017 um 09:51 schrieb Kaartic Sivaraam:
Show 26 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.
> 
> It's not a big issue as I haven't lost anything out of it. The branches
> have been merged into 'master'.
> 
> 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
> 
See, these two are different:

$ echo '✓doc-fix' | cut -c3-100 | od -t x1 0000000 93 64 6f 63 2d 66 69 78 0a 0000011 $ echo '�doc-fix' | od -t x1 0000000 64 6f bd 64 6f 63 2d 66 69 78 0a 0000013

It is not Git's fault that your terminal converts an invalid UTF-8 sequence (that your script produces) to �. Nor is it when you paste that character onto the command line, that it is passed as a (correct) UTF-8 character.

Perhaps this helps (untested):
$ git branch -m done/$(printf '\x93')doc-fix done/dic-fix

In Git's database, branch names are just sequences of bytes. It is outside the scope to verify that all input is encoded correctly.

-- Hannes
Previous: Kaartic SivaraamNext: Kaartic Sivaraam
Message 2 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.