Git for windows 中文乱码解决方案

1.使用 git add 命令添加文件名含中文字符的文件时

乱码类似:

316304261276316304265265.txt

解决方案:

编辑C:Gitetcinputrc文件中对应的行, 
查找以下2行,并修改其值, 
原先:

set output-meta off
set convert-meta on

改为:

set output-meta on
set convert-meta off

2.使用git log查看含有中文的log信息时

乱码类似:

<E4><BF><AE><E6><94><B9><E6><96><87><E6><9C><AC><E6><96><87><E6><A1><A3>

解决方案:

在Bash提示符下输入:

git config --global i18n.commitencoding utf-8
git config --global i18n.logoutputencoding gbk

注:设置commit提交时使用utf-8编码,可避免Linux服务器上乱码;同时设置在执行git log时将utf-8编码转换成gbk编码,以解决乱码问题。 
编辑C:Gitetcprofile文件,添加如下一行:

export LESSCHARSET=utf-8

注:以使git log可以正常显示中文(需要配合:i18n.logoutputencoding gbk)

3.使用ls命令查看含有中文的文件名乱码时

乱码类似:

????.txt

解决方案:

使用 ls –show-control-chars 命令来强制使用控制台字符编码显示文件名,即可查看中文文件名。 
为了方便使用,可以编辑 C:Gitetcgit-completion.bash 文件,添加如下一行:

alias ls="ls --show-control-chars"

4.在Git Gui中查看UTF-8编码的文本文件时

乱码类似:
锘夸腑鏂囨枃妗£

解决方案:

在Bash提示符下输入:

git config --global gui.encoding utf-8

注:通过上述设置,UTF-8编码的文本文件可以正常查看,但是GBK编码的文件将会乱码,所以还是没有从根本上解决问题。

可行的方法之一为:将所有文本文件的编码统一为UTF-8或GBK,然后设置相应的gui.encoding参数为utf-8或gbk。

原文地址:https://www.cnblogs.com/simpman/p/4128396.html