[原创] How to show chinese character in Git Status

如何在 Git Status 中显示中文文件名

When I created some file which contains Chinese Character and wanted to show which files were untracked using git status, some unrecognized character were shown there:


$ touch 测试

$ git status

On branch pink-page

Untracked files:

(use "git add <file>..." to include in what will be committed)

"\346\265\213\350\257\225"

This is very inconvenient for snapshot. Remember the filename is impossible.

Fortunately, you can use git-config to solve this problem.


$ git config --global core.quotePath false

$ git status

On branch pink-page

Untracked files:

(use "git add <file>..." to include in what will be committed)

测试

It’s amazing! The reason behind this miracle is:

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 \302\265 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.

Any of the Chinese character’s byte value is obviously larger than 0x80 (i.e. 128 in decimal), so all these characters in pathname will not be human readable if core.quotePath is true (default).

Reference

How to convert 0x80 in to 128?

本作品采用《CC 协议》,转载必须注明作者和本文链接
日拱一卒
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
93
粉丝
85
喜欢
153
收藏
121
排名:71
访问:11.4 万
私信
所有博文
社区赞助商