在 Windows 上使用 Git Bash,如何签出以 Unicode 字符开头的分支?

Using Git Bash on Windows, how do I checkout a branch that begins with a Unicode character?

我正在使用 git bash.

我创建了一个分支,做了一些更改并提交了。当我试图推动时,它给了我:

error "refpath does not exist".

然后我结账到其他分行并重新尝试结账到我的分行但它说

error: pathspec 'tabViewComponent' did not match any file(s) known to git.

我做了 git branch,它给了我这样的分支名称:

参考https://www.htmlsymbols.xyz/unicode/U+0096,我看到分支名称的开头包含。你能试试git checkout –tabViewComponent吗?不确定它是否是有效的分支名称。

分支名称以 Unicode 字符 'START OF GUARDED AREA' (U+0096) 开头,很难与普通的破折号字符 (-) 区分开来,只是在我使用的字体上稍宽一些。

在命令提示符处输入 Unicode 字符的方式因平台而异。您可以从上面链接的页面(或下面的命令)复制它或使用适合您平台的撰写序列。

git checkout –tabViewComponent

On Windows, entering Unicode 默认为

Unicode characters can then be entered by holding down Alt, pressing the + on the numeric keypad, followed by the hexadecimal code – using the numeric keypad for digits from 0 to 9 and letter keys for A to F digits – and then releasing Alt.

这不是一个特别友好的分支名称,因为检查它会很麻烦,而且如果有人试图使用前导破折号会导致混淆。我强烈建议重命名它以删除前导 U+0096。

我建议您在推送之前检出该分支并重命名它: 用数字键盘

git checkout ALT+96tabViewComponent
git branch -m ALT+96tabViewComponent:tabViewComponent

ALT+96 上不要忘记加号,如果你得到“`”作为输出,你忘记了加号(Unicode字符应该不可见

编辑: ALT+96表示START OF GUARDED AREA是一个控制字符,你也可以得到相同的字符Alt 0150

如果您是 java 人:

System.out.println("->\u0096<-");

只需复制输出箭头之间的死角

Reference