37

I have a file with Swedish characters in it (åäö) encoded with UTF8.

If I cat the file it displays fine, but if I do git diff the special characters are printed, for example, as <F6>.

Example git diff output:

-            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 answers It says all problems should be fixed in git version 1.7.10. I have version 1.8.1.2

What can I do to make git diff properly display åäö?

4

3 回答 3

70

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:

LESSCHARSET=UTF-8
于 2013-10-17T20:17:55.393 回答
4

@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)...

iconv -f ISO-8859-1 -t UTF-8 in.txt > out_utf-8.txt

solved my issue

于 2013-10-17T20:35:52.543 回答
3

git log will be opened by less not vi.

So you should set lang to less.

$ export LESSCHARSET=utf-8 && git log

于 2016-08-04T04:21:21.517 回答