如何在OS X上的Git中处理文件名中的亚洲字符

Mot*_*Mot 39 git unicode macos non-ascii-characters

我使用的是美国英语OS X 10.6.4,并尝试在Git存储库中存储名称中包含亚洲字符的文件.

好的,让我们在Git工作树中创建这样一个文件:

$ touch ????????????????.txt
Run Code Online (Sandbox Code Playgroud)

Git将它显示为八进制转义的UTF-8格式:

$ git version
git version 1.7.3.1
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   "\343\201\250\343\202\231\343\201\206\343\202\202\343\201\202\343\202\212\343\201\213\343\202\231\343\201\250\343\201\206\343\203\237\343\202\271\343\202\277\343\203\274\343\203\255\343\203\233\343\202\231\343\203\203\343\203\210.txt"
nothing added to commit but untracked files present (use "git add" to track)
Run Code Online (Sandbox Code Playgroud)

不幸的是,我无法将其添加到Git存储库:

$ git add ????????????????.txt
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   "\343\201\250\343\202\231\343\201\206\343\202\202\343\201\202\343\202\212\343\201\213\343\202\231\343\201\250\343\201\206\343\203\237\343\202\271\343\202\277\343\203\274\343\203\255\343\203\233\343\202\231\343\203\203\343\203\210.txt"
nothing added to commit but untracked files present (use "git add" to track)
Run Code Online (Sandbox Code Playgroud)

Git只是忽略了这个文件.

使用通配符工作:

$ git add *.txt
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   "\343\201\250\343\202\231\343\201\206\343\202\202\343\201\202\343\202\212\343\201\213\343\202\231\343\201\250\343\201\206\343\203\237\343\202\271\343\202\277\343\203\274\343\203\255\343\203\233\343\202\231\343\203\203\343\203\210.txt"
#
Run Code Online (Sandbox Code Playgroud)

但我想从一个特定文件名的应用程序调用Git命令.我没有选择发明与此文件完全匹配的通配符模式,但没有其他人.

这是Git的已知错误还是我没有正确使用Git?

Dav*_*ogt 62

Git默认引用任何非ascii字符,而不仅仅是亚洲字符.可以选择禁用此引用行为.

您可以使用以下命令禁用它:

git config --global core.quotepath false
Run Code Online (Sandbox Code Playgroud)

或者,通过将以下代码段添加到您的git配置文件(通常为$ HOME/.gitconfig)

[core]
    quotepath = false
Run Code Online (Sandbox Code Playgroud)

在此之后,git应该完全按原样显示您的文件名.

至于你的另一个问题,git没有添加带有亚洲字符的文件,我只能猜测它与git使用的编码有关,与你的终端使用的编码不同.我希望其他人可以跳进去解释一下.