文件名显示乱码怎么办(解决git status显示中文文件名乱码问题)(1)

使用 git status 查看本地有改动但未提交的中文文件名时,发现会显示为一串数字,没有显示中文的文件名。具体如下所示:

$ git status
# 位于分支 master
# 尚未暂存以备提交的变更:
# (使用 "git add <file>..." 更新要提交的内容)
# (使用 "git checkout -- <file>..." 丢弃工作区的改动)
#
# 修改: "\224\257\346\216\247\345\210\266\346\265\201.txt"

解决方案是设置 git 的 core.quotepath 选项为false:

git config --global core.quotepath false

查看git在线帮助手册 (https://git-scm.com/docs/git-config),里面对 core.quotepath 选项说明如下:

core.quotePath

Commands that output paths (e.g. ls-files, diff), will quote "unusual" characters in the pathname by enclosing the pathname in double-quotes and escaping those characters with backslashes in the same way C escapes control characters (e.g. t for TAB, n for LF, \ for backslash) or bytes with values larger than 0x80 (e.g. octal 302265 for "micro" in UTF-8). If this variable is set to false, bytes higher than 0x80 are not considered "unusual" any more. Double-quotes, backslash and control characters are always escaped regardless of the setting of this variable. A simple space character is not considered "unusual". Many commands can output pathnames completely verbatim using the -z option. The default value is true.

即,core.quotepath 选项为 true 时,会对中文字符进行转义再显示,看起来就像是乱码。设置该选项为false,就会正常显示中文。

在一些终端上还要检查它自身的语言设置,看终端是否可以正常显示中文。