今天使用 Mac Terminal 時,解決了兩個中文亂碼的問題,記錄一下。git
今天,整理博客文章的時候,發現 git status 展現中文名的文件出現了亂碼。由於平時編程時,代碼文件的名稱基本都是英文,故而不多留意這個問題。默認的 git status 效果以下:編程
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
"\346\227\245\345\270\270/"
nothing added to commit but untracked files present (use "git add" to track)
複製代碼
在網上搜了些解決方案,發現只須要一個 git 配置就能夠解決這個問題,配置命令以下:api
$ git config --global core.quotepath false
複製代碼
關於這個選項的介紹,官方原文以下:bash
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 -zoption. The default value is true.架構
大體意思彷佛是, 爲防止一些轉義問題,大於 0x80 以上的編碼被認爲是 "unusual" ,須要 quote 起來。設置成 false 即以 UTF8 編碼解析,解決亂碼問題。less
真是奇了,亂碼與我爲敵啊!今天又遇到第二個亂碼問題,爲了寫文章時,屏幕展現區域多點,我就把 VS Code 的側邊欄關了,而後經過 tree 查看目錄樹,結果出現了以下的結果:ide
.
├── Go\ �\210��\231�
│ └── Go\ �\210��\231��\213HTTP請�\202\ QuickStart.md
├── Go\ �\224記
│ ├── 詳解\ Go\ �\232\204�\226�\221�\211��\214�\201�\213.md
│ └── 爲�\200�\210�\201學\ Go.md
├── Go\ �\217�\237��\206
├── README.md
├── �\227�常
│ └── Mac\ �\216��\210��\217�中�\226\207亂�\201�\232\204兩個�\235\221.md
└── �\204件
├── pm2\ �\233�\213管�\220\206工�\205�使�\224��\200��\223.md
├── �\200�\226\207精�\200\232\ crontab\ �\216�\205��\227��\210��\207��\235\221.md
└── 快�\200\237�\206解\ kafka\ �\237��\200�\236��\236\204.md
複製代碼
解決方式,經過 tree -N 便可解決。執行結果以下:工具
├── Go 爬蟲
│ └── Go 爬蟲之HTTP請求 QuickStart.md
├── Go 筆記
│ ├── 詳解 Go 的編譯執行流程.md
│ └── 爲何要學 Go.md
├── Go 小知識
├── README.md
├── 平常
│ └── Mac 控制檯中文亂碼的兩個坑.md
└── 組件
├── pm2 進程管理工具使用總結.md
├── 一文精通 crontab 從入門到出坑.md
└── 快速瞭解 kafka 基礎架構.md
複製代碼
看了選項的介紹,彷佛是由於默認會將一些非打印字符按 ?處理,能夠去看看 -q 選項。ui