Linux

在命令行下输入以下命令:
$ 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添加环境变量。

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,直接添加环境变量LESSCHARSET,变量值utf-8,重启电脑让变量生效。
不重启电脑快速测试的话,cmd输入命令
set LESSCHARSET=utf-8
用Git bash的看参考二。

参考
解决 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/
网友评论