'git log output encoding issues on Windows 10 CLI terminal

Problem

How to make git log command output properly displayed on Windows CLI terminal?

Example

git commands sequence leading to the problem As you can see I can type diacritical characters properly but on git log the output is somehow escaped. According to UTF-8 encoding table the codes between angled brackets (< and >) from the output correspond to the previously typed git config parameters.

I have tried to set LESSCHARSET environment variable to utf-8 as sugested in one of the answers for similar issue but then the output is garbled:

git log output after setting LESSCHARSET=utf8

I know .git/config is encoded properly with utf-8 as it's handled by gitk as expected.

Proper gitk output

Here is locale command output if necessary

LANG=
LC_CTYPE="C.UTF-8"
LC_NUMERIC="C.UTF-8"
LC_TIME="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_MONETARY="C.UTF-8"
LC_MESSAGES="C.UTF-8"
LC_ALL=

EDIT:

The output is the same also in pure git-bash:

enter image description here

so I believe the problem is shell independent and relates to Git or its configuration itself.



Solution 1:[1]

If anyone is interested in the PowerShell equivalent of set LC_ALL=C.UTF-8, that is:

$env:LC_ALL='C.UTF-8'

However this works only for the current session. To make it permanent, two possibilities:

  • create an environment variable named LC_ALL with the value C.UTF-8
  • or put $env:LC_ALL='C.UTF-8' in your $Profile file

Solution 2:[2]

I am using Git via Powershell Core v7.0.3 inside Windows Terminal on Windows 10.

I have been browsing through answers and tried many of them. The solutions that worked for me were:

These solutions both work separately. I chose to use the Git command as the problem seems to be related to Git, and Powershell profile stays cleaner.

Solution 3:[3]

I use git bash on WIN10. As for me, 4 settings make the appearance as my expectation.

  • env setting. Add LC_ALL=C.UTF-8,LESSCHARSET=UTF-8 to PATH globally.

  • git config. git config --global i18n.logOutputEncoding utf-8.

  • git bash setting. Set Options-> Text-> Character set to utf-8. Or set locale and Character set both to default. It is smart enough to choose the correct encoding.

Done.

Solution 4:[4]

I had such problem on Linux. And the problem was that I did not generated locales. So my output of locale was cantaining all "C" letters, without UTF-8. To solve this, I uncommented en_US.UTF-8 and ru_RU.UTF-8 in /etc/locale.gen. Then I run localectl set-locale LANG=ru_RU.UTF-8 and rebooted. And relogined to the system. After that ciryllic was displayed normally.

Solution 5:[5]

I had to use the windows powershell command prompt instead of the default one (Windowkey + X)

Solution 6:[6]

git config --global core.pager 'less --raw-control-chars'
 
#Or

git config --global core.pager 'more'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andrew Spencer
Solution 2
Solution 3
Solution 4 Ashark
Solution 5 john ktejik
Solution 6 DEV Tiago França