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

发布于 2024-10-01 09:16:39 字数 1828 浏览 0 评论 0原文

我使用的是美式英语 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?

I'm on US-English OS X 10.6.4 and try to store files with Asian characters in its name in a Git repository.

OK, let's create such a file in a Git working tree:

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

Git is showing it as octal-escaped UTF-8 form:

$ 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)

Unfortunately, I'm not able to add it to the Git repository:

$ 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 simply ignored this file.

Using wildcards work:

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

but I want to invoke the Git command from an application for a specific file name. I don't have the option to invent wildcard patterns which match exactly this file, but no one else.

Is this a known bug of Git or me not using Git correctly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空心空情空意 2024-10-08 09:16:39

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

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

git config --global core.quotepath false

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

[core]
    quotepath = false

之后,git 应该准确显示您的文件名。

至于你的另一个问题,git 没有添加带有亚洲字符的文件,我只能猜测它与 git 使用的编码与你的终端使用的编码不同有关。我希望其他人能够介入并解释这一点。

Git quotes any non-ascii character by default, not only asian ones. There's an option to disable this quoting behaviour.

You can disable it using the following command:

git config --global core.quotepath false

Or, alternatively, by adding the following snippet to your git config file ($HOME/.gitconfig usually)

[core]
    quotepath = false

After this, git should show your filenames exactly as they are.

As to your other problem, git not adding a file with asian characters, I can only guess that it has to do with the encoding that git uses is not the same as the encoding your terminal uses. I hope someone else can jump in and explain that bit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文