50

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

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

$ touch どうもありがとうミスターロボット.txt

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)

不幸的是,我无法将它添加到 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)

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"
#

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

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

4

1 回答 1

80

Git 默认引用任何非 ascii 字符,不仅是亚洲字符。有一个选项可以禁用此引用行为。

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

git config --global core.quotepath false

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

[core]
    quotepath = false

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

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

于 2010-12-11T12:51:07.917 回答