Linux

git diff正文中文亂碼
在命令行下輸入以下命令:
$ git config --global core.quotepath false # 顯示 status 編碼
$ git config --global gui.encoding utf-8 # 圖形界面編碼
$ git config --global i18n.commit.encoding utf-8 # 提交信息編碼
$ git config --global i18n.logoutputencoding utf-8 # 輸出 log 編碼
$ export LESSCHARSET=utf-8
# 最后一條命令是因為 git log 默認使用 less 分頁,所以需要 bash 對 less 命令進行 utf-8 編碼
想長期生效的 話要改profile添加環(huán)境變量。

修復git diff正文中文亂碼
Windows
在命令行下輸入以下命令:
$ git config --global core.quotepath false # 顯示 status 編碼
$ git config --global gui.encoding utf-8 # 圖形界面編碼
$ git config --global i18n.commit.encoding utf-8 # 提交信息編碼
$ git config --global i18n.logoutputencoding utf-8 # 輸出 log 編碼
我使用cmd,直接添加環(huán)境變量LESSCHARSET,變量值utf-8,重啟電腦讓變量生效。
不重啟電腦快速測試的話,cmd輸入命令
set LESSCHARSET=utf-8
用Git bash的看參考二。

Windows修復git diff正文中文亂碼
參考
解決 Git 在 windows 下中文亂碼的問題
https://gist.github.com/nightire/5069597
g4e常見問題#4 解決Git在Windows上的中文亂碼問題 | DevOps 博客
https://devopshub.cn/2018/01/07/g4e-faq-4-git-encoding-error/