git log的中文乱码问题


PowerShell交流中心分类: Powershell基础git log的中文乱码问题
0
monk_q asked 8 年 ago

在PS,下输入命令git log能够正常显示.
不过
$log = git log
$log
输出的内容中文是乱码

1 Answers
0
Best Answer
Mooser Lee 管理员 answered 8 年 ago

请把Git控制台的默认输出改为gbk编码:

git config --global i18n.logoutputencoding gbk

测试过程:
安装完git,提交一个包含中文的描述的changes,在PS中查看log

PS> & "C:\Program Files (x86)\Git\bin\git.exe" log
commit 54e5e2497267c8f04235dffbcd76f98ebfe0ae4f
Author: Baozhen Li <Baozhen Li>
Date: Mon Jun 27 23:33:24 2016 +0800

PowerShell中文博客测试

Signed-off-by: Baozhen Li <Baozhen Li>

commit 80020d57fac60b22872f4b202c7ef8977348a389
Author: Baozhen Li <Baozhen Li>
Date: Mon Jun 27 23:31:04 2016 +0800

Signed-off-by: Baozhen Li <Baozhen Li>

保存到变量,再测试,发现中文字符乱码:

PS> $s=& "C:\Program Files (x86)\Git\bin\git.exe" log
PS> $s
commit 54e5e2497267c8f04235dffbcd76f98ebfe0ae4f
Author: Baozhen Li <Baozhen Li>
Date: Mon Jun 27 23:33:24 2016 +0800

PowerShell涓枃鍗氬娴嬭瘯

Signed-off-by: Baozhen Li <Baozhen Li>

commit 80020d57fac60b22872f4b202c7ef8977348a389
Author: Baozhen Li <Baozhen Li>
Date: Mon Jun 27 23:31:04 2016 +0800

Signed-off-by: Baozhen Li <Baozhen Li>

打开git bush,运行上面的配置:

git config --global i18n.logoutputencoding gbk

再次测试:

PS> $a=& "C:\Program Files (x86)\Git\bin\git.exe" log
PS> $a
commit 54e5e2497267c8f04235dffbcd76f98ebfe0ae4f
Author: Baozhen Li <Baozhen Li>
Date: Mon Jun 27 23:33:24 2016 +0800

PowerShell中文博客测试

Signed-off-by: Baozhen Li <Baozhen Li>

commit 80020d57fac60b22872f4b202c7ef8977348a389
Author: Baozhen Li <Baozhen Li>
Date: Mon Jun 27 23:31:04 2016 +0800

Signed-off-by: Baozhen Li <Baozhen Li>