git 使用时有时出现中文显示乱码。
git bash 中文乱码问题
点击git bash 窗口左上角的图标,选择 Options,选择其中的 Text 项,选择其中的 Locale 为 zh_CN,Character Set 为 UTF-8:
git命令中文显示乱码问题
在 Windows 命令行,或者Windows PowerShell时,使用 git 出现乱码时,输入如下git 全局变量设置:
git config --global core.quotepath false
git config --global gui.encoding utf-8
git config --global i18n.commitEncoding utf-8
git config --global i18n.logoutputEncoding utf-8
git config --global core.quotepath false 表示 git 遇到中文的文件路径,不做转义操作。
git config --global gui.encoding utf-8 表示在 git-gui 和 gitk 中显示文件内容时采用的默认字符集。
git config --global i18n.commitEncoding utf-8 表示设置提交信息按什么字符集存储。本质上,git本身不关心字符集,但当从Email 提交的时候,或者在 gitk 图形窗口浏览提交历史的时候,就很重要。
git config --global i18n.logoutputEncoding utf-8 当执行 git log 等命令时,提交信息被转换为何种字符集。
还需要设置 LESSCHARSET 环境变量
LESSCHARSET 设置为 utf-8.
Linux 设置到用户的 .profile 或者系统 .profile 中,export LESSCHARSET=utf-8。例如:
echo "export LESSCHARSET=utf-8" > $HOME/.profile
source $HOME/.profile
Windows 设置到用户环境变量或者系统环境变量: