如何在OS X上的Git中处理文件名中的亚洲字符 [英] How to handle Asian characters in file names in Git on OS X

查看:195
本文介绍了如何在OS X上的Git中处理文件名中的亚洲字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用美式英文版操作系统X 10.6.4,并尝试在Git存储库中以亚洲字符名称存储文件。



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

  $ touchどうもありがとうタットボット.txt 

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

<$ p $ $ git版本
git版本1.7.3.1
$ git status
#分支主

#初始提交

#未记录的文件:
#(使用git add< 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 add跟踪)

我无法将其添加到Git存储库中:

  $ git addううもありがとうミターロボット.txt 
$ git status
#分支大师

#初始提交

#未记录文件:
#(使用git add< 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 add来跟踪)

Git简单地忽略了这个文件。 / p>

使用通配符工作:

  $ git add * .txt 
$ git status
#在分支master上

#初始提交

#要提交的更改:
#(使用git rm --cached< 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的已知错误?

解决方案

Git默认引用任何非ascii字符,不仅是亚洲字符。您可以使用以下命令禁用它:

  git config --global core.quotepath false 

或者, ($ HOME / .gitconfig通常)

  [core] 
quotepath =假

之后,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?

解决方案

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.

这篇关于如何在OS X上的Git中处理文件名中的亚洲字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆