如何让 Git 在控制台窗口中正确显示 UTF-8 编码的路径名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22827239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make Git properly display UTF-8 encoded pathnames in the console window?
提问by exebook
I have file names in UTF-8, git handles them O.K, it will create files properly and github pages also display it right. Except that it will display it in console like below. Is it possible to make git display UTF-8 encoded characters beyond ASCII 127 in console properly?
我有 UTF-8 格式的文件名,git 可以正常处理它们,它会正确创建文件并且 github 页面也能正确显示。除了它会在控制台中显示它,如下所示。是否可以让 git 在控制台中正确显示超出 ASCII 127 的 UTF-8 编码字符?
git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: .gitignore
# modified: editfile.js
# modified: "13111200050602"
#
no changes added to commit (use "git add" and/or "git commit -a")
UPDATE
更新
I have been asked about my locale, here is the output of locale
command
我被问到我的语言环境,这是locale
命令的输出
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
回答by VonC
git has always used octal utf8 display, and one way to show the actual name is by using printf
in a bash shell.
git 一直使用八进制 utf8 显示,显示实际名称的一种方法是printf
在 bash shell 中使用。
According to this comment, this works even in a Windows msysgit bash, which does include printf
(and can be used as in "How do I use octal characters in a git checkout?").
根据这个评论,这甚至在 Windows msysgit bash 中也能工作,它包含printf
(并且可以在“我如何在 git checkout 中使用八进制字符?”中使用)。
But that doesn't change the output of commands like git status
or git ls-files
.
However, since Git 1.7.10 introduced the support of unicode, this wiki pagementions:
但这不会改变像git status
or之类的命令的输出git ls-files
。但是,由于 Git 1.7.10 引入了对 unicode 的支持,因此这个wiki 页面提到:
By default, git will print non-ASCII file names in quoted octal notation, i.e. "
\nnn\nnn...
". This can be disabled with:
默认情况下,git 会以带引号的八进制表示法打印非 ASCII 文件名,即“
\nnn\nnn...
”。这可以禁用:
git config core.quotepath off
Or for all repositories using:
或者对于所有存储库使用:
git config --global core.quotepath off
Keep in mind that:
请记住:
The default console font does not support Unicode. Change the console font to a TrueType font such as Lucida Console or Consolas.
The setup program can do this automatically, but only for the installing user.
默认控制台字体不支持 Unicode。将控制台字体更改为 TrueType 字体,例如 Lucida Console 或 Consolas。
安装程序可以自动执行此操作,但仅限于安装用户。