使 git diff 正确显示 UTF8 编码的字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19435071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Make git diff show UTF8 encoded characters properly
提问by Tobbe
I have a file with Swedish characters in it (???) encoded with UTF8.
我有一个用 UTF8 编码的文件,其中包含瑞典语字符 (???)。
If I cat
the file it displays fine, but if I do git diff
the special characters are printed, for example, as <F6>.
如果我cat
的文件显示正常,但如果我git diff
打印特殊字符,例如 <F6>。
Example git diff
output:
示例git diff
输出:
- name: 'Magler<F6>d, S<F6>der<E5>sen',
What I wanted to see:
我想看到的:
- name: 'Magler?d, S?der?sen',
I found another question related to git and encoding problems: git, msysgit, accents, utf-8, the definitive answersIt says all problems should be fixed in git version 1.7.10. I have version 1.8.1.2
我发现了另一个与 git 和编码问题相关的问题:git、msysgit、accents、utf-8,最终答案它说所有问题都应该在 git 版本 1.7.10 中修复。我有 1.8.1.2 版
What can I do to make git diff properly display ????
我该怎么做才能使 git diff 正确显示???
采纳答案by Tobbe
@matt and @twalberg were correct. The file wasn't actually UTF-8 encoded. Trying to figure this out wasn't helped by the fact that my terminal (hterm) can't input ??? properly (but it can display and copy/paste them)...
@matt 和 @twalberg 是正确的。该文件实际上不是 UTF-8 编码的。我的终端(hterm)无法输入 ??? 正确(但它可以显示和复制/粘贴它们)...
iconv -f ISO-8859-1 -t UTF-8 in.txt > out_utf-8.txt
solved my issue
解决了我的问题
回答by Edward Thomson
git
is dumping out raw bytes. In this case, it doesn't care what your file's encoding is. The highlighted <F6>
you're seeing is coming from less
, which is presumably configured as your PAGER
. Try setting:
git
正在转储原始字节。在这种情况下,它不关心您的文件的编码是什么。<F6>
您看到的突出显示来自less
,大概配置为您的PAGER
. 尝试设置:
LESSCHARSET=UTF-8
回答by kujiy
git log will be opened by less not vi.
git log 将被 less 而不是 vi 打开。
So you should set lang to less.
所以你应该将lang设置为less。
$ export LESSCHARSET=utf-8 && git log
$ export LESSCHARSET=utf-8 && git log