解決git status顯示中文文件名亂碼問題

使用 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-...),裏面對 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,就會正常顯示中文。

在一些終端上還要檢查它自身的語言設置,看終端是否可以正常顯示中文。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章