101

Problem

How can I make git log command output properly displayed in the 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 the UTF-8 encoding table, the codes between angle 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 suggested 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 the 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=

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Marcin Kłopotek
  • 5,271
  • 4
  • 31
  • 51
  • 2
    Have you tried the solution in "[Unicode characters in Windows command line - how?](http://stackoverflow.com/questions/388490/unicode-characters-in-windows-command-line-how)"? – jthill Dec 31 '16 at 00:01
  • Yes, I tried several code pages including 65001 (UTF-8) without any result. It seems chcp command has no influence on how git log output is displayed. It's always displayed in the same way. – Marcin Kłopotek Dec 31 '16 at 13:54
  • 1
    Sorry if the question sounds stupid, but why do you use the Windows command prompt at all instead of Git Bash? It is better suited to using Git, the window is resizeable up to full screen, the prompt automatically shows you which branch you are on etc. – kriegaex Jan 01 '17 at 14:09
  • 1
    It's not stupid @kriegaex, it's good actually. I'm using git-bash wrapped into ConEmu for everyday use. The result is the same http://i.imgur.com/hMKz9D3r.png. I've described my problem giving examples with cmd.exe to not confuse people with other dependent tools am using as I believe the problem is shell independent and relates to Git or its configuration itself. – Marcin Kłopotek Jan 01 '17 at 14:24
  • @jthill thanks, this answer seems to do it, https://stackoverflow.com/a/55674760/4592648 – Monday Fatigue Jan 05 '22 at 10:48

7 Answers7

175

Okay, I experimented a bit and found out that Windows Git commands actually need UNIX variables like LC_ALL in order to display Polish (or other UTF-8 characters) correctly. Just try this command:

set LC_ALL=C.UTF-8

Then enjoy the result. Here is what happened on my console (font "Consolas", no chcp necessary):

Windows console CMD


Update:

  • Well, in order for Windows commands like type (display file on console) to work correctly, you do need chcp 65001.
  • And if you prefer commands from Git Bash like cat you profit from the aforementioned set LC_ALL=C.UTF-8.

Windows console CMD, part 2


Update 2: How to make the changes permanent

As user mono blaine said, create an environment variable LC_ALL and assign it the value C.UTF-8, either globally or for your own user profile only (sorry for the German screenshot):

Create environment variable

Next time you open a command processor console (cmd.exe) you should see the variable value when issuing the command echo %LC_ALL%. In PowerShell you should see it when issuing $env:LC_ALL.

The simplest way to make the UTF-8 code page permanent ist to open regeedit and add a new value named Autorun of type string to section HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor and assign it the value chcp 65001.

Registration editor

Henceforth, this command will be executed each time you open a new cmd.exe console. You even see its output in the new window: "Aktive Codepage: 65001." (or similar in your respective language).

Oh, by the way: In order to display a UTF-8 encoded file correctly in PowerShell you can use Get-Content -encoding UTF8 file.txt or cat -encoding UTF8 file.txt (cat being an alias for Get-Content in PowerShell).

kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • Set `LC_ALL` is not needed by git itself. Other tools -- shiped with the git installaion -- like `less`, which is the default pager / see [core.pager](https://git-scm.com/book/gr/v2/Customizing-Git-Git-Configuration) are using the `LC_ALL` value. Other valid values are the localized lang e.g.: `LC_ALL=de_DE.UTF-8` for the germans. – return42 Nov 04 '17 at 13:41
  • 1
    you can set the environment-variable from commandline using `setx LC_ALL C.UTF-8` – anion Apr 14 '19 at 17:49
  • Powershell 6 in ConEmu, it was enough to add `$env.LC_ALL='ClUTF-8'` to `$Profile` – Andrew Spencer Feb 19 '20 at 09:51
  • Had encoding issue with rscript utility (command line tool for running r code), this advice helped to fix it also. Thanks! – SliceOfTuna Sep 28 '21 at 02:21
73

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
Andrew Spencer
  • 15,164
  • 4
  • 29
  • 48
mono blaine
  • 1,001
  • 9
  • 13
  • 1
    Or add it to your PowerShell profile (I prefer this to the global setting because I use the same profile – via git – on multiple machines). – Richard Nov 21 '17 at 11:29
  • 3
    The profile file can be edited by for example running: notepad $profile Then add a line somewhere as mono blaine suggested, $env:LC_ALL='C.UTF-8' – Tore Aurstad Sep 25 '18 at 08:58
  • With PowerShell 6 + ConEmu on Windows 10: this works, nothing else was needed – Andrew Spencer Feb 19 '20 at 09:55
11

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ayşe Nur
  • 493
  • 7
  • 11
  • 1
    Thanks for the Git setting. The Git settings works for me, but also found that setting `$env:LESSCHARSET='utf-8'` works fine as well for the PowerShell 5 in the Windows Terminal. – mloskot Sep 28 '20 at 09:40
7

I use Git Bash on Windows 10. As for me, four 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 OptionsTextCharacter set to utf-8. Or set locale and Character set both to default. It is smart enough to choose the correct encoding.

Done.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
W.Perrin
  • 4,217
  • 32
  • 31
1

I had to use the Windows PowerShell command prompt instead of the default one (Windows key + X).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
john k
  • 6,268
  • 4
  • 55
  • 59
1

I had such problem on Linux. And the problem was that I did not generate locales. So my output of locale was containing 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 Cyrillic was displayed normally.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ashark
  • 643
  • 7
  • 16
0
git config --global core.pager 'less --raw-control-chars'
 
#Or

git config --global core.pager 'more'
DEV Tiago França
  • 1,271
  • 9
  • 9