📜 ⬆️ ⬇️

Git settings for windows

Problems with Russian characters in git

When you start working with the git version under windows in the command line, you will encounter the following problem - all the git messages in which Russian characters appear will be unreadable. The file names in Russian will look like this - "\ 362 \ 345 \ 361 \ 362" , and the commit texts like this - <C8> <ED> <E8> <F6> <E8> <E0> <EB> < E8> <E7> <E0> <F6> <E8> <FF> <EF> <F0> <EE> <E5> <EA> <F2> <E0> . Those. the source string is converted to utf8 according to the latin1 encoding.


Troubleshooting

For example, I created the rep directory on the C: drive, created a new file in it called test, and initialized a new repository. After that, added to the repository all the files from the current directory.
 C: \ rep> git init
 Initialized empty Git repository in C: /rep/.git/

 C: \ rep> git add.


It can be seen that the files with Russian letters are not shown in the encoding in which we could read them without problems.
 C: \ rep> git status
 # On branch master
 #
 # Initial commit
 #
 # Untracked files:
 # (use "git add <file> ..." to be in what will be committed)
 #
 # "\ 362 \ 345 \ 361 \ 362"
 untracked files present (use "git add" to track)


To correct this git behavior, you must change the quotepath parameter in the [core] section to set it to false .
quotepath = false


NB: You can change either the global settings file or the local one.
')
The global configuration file is here: C: \ Program Files \ Git \ etc \ gitconfig, local in the repository directory .git \ config.

The following problem occurs when editing the commit description.
 C: \ rep> git commit -a -s


If you edit and save the commit in 8-bit encoding, the following message appears:
 Warning: commit message does not conform to UTF-8.
 Fix it after fixing the message
 variable i18n.commitencoding to the encoding your project uses.
 [master (root-commit) cc05f8a] Signed-off-by: maslakov <maslakov@mail.local>
  1 files changed, 1 insertions (+), 0 deletions (-)
  create mode 100644 "\ 362 \ 345 \ 361 \ 362"


Accordingly, it is necessary to specify the encoding in which the description of the commits will be entered, in the [i18n] section, the commitencoding parameter
commitencoding = cp1251

The third problem that arises when working with the git console interface is to log output:
 C: \ rep> git log


by default it looks like this
 commit cc05f8a470e8602ded60ba9c979c93148b334d4e
 Author: maslakov <maslakov@mail.local>
 Date: Tue Nov 10 12:37:38 2009 +0300
     <C8> <ED> <E8> <F6> <E8> <E0> <EB> <E8> <E7> <E0> <F6> <E8> <FF> <EF> <F0> <EE> <E5 > <EA> <F2> <E0>
     Signed-off-by: maslakov <maslakov@mail.local>


As the utility of “ less guilty” showed, the opening of this “fault” means that setting the environment variable LESSCHARSET = koi8-r will help convince it to show the text or you can simply specify the utility cat as a viewer. To display the text page by page, transfer the output of the cat utility to the more utility.
In addition, you must specify the logoutputencoding parameter in the [i18n] section
logoutputencoding = cp866

In principle, after installing the above settings, the main problems of using national languages, in 8-bit encodings, will be solved.
Here is my \ .git \ config file
 [core]
         repositoryformatversion = 0
         filemode = false
         bare = false
         logallrefupdates = true
         symlinks = false
         ignorecase = true
         quotepath = false 
         pager = cat | more.com
         editor = far -e
 [i18n]
         commitencoding = cp1251
         logoutputencoding = cp866



I edit the commit text in far, so the editor parameter is defined as far -e

I hope someone this information will be useful ...

UPD: thanks to Alexey Shumkin for addition
ashu> less
www.linuxcenter.ru/lib/books/kostromin/gl_11_05.phtml
- LESSCHARSET=koi8-r ( Cygwin 1.5 )


UPD2: hokum thanks for the addition
Unfortunately, these solutions did not help to overcome the problem with the output of Russian characters in the output of the git diff, git show commands.

To the installed Git, I copied the iconv.exe to the bin directory, and wrote to Git's config:
pager = iconv.exe -f cp1251 -t utf-8 | less
I have project files in cp1251, respectively.

The iconv.exe file can be found by downloading the archive with the iconv project’s binary files under Windows gnuwin32.sourceforge.net/packages/libiconv.htm .
In addition to it, you need dll:
libcharset1.dll
libiconv2.dll (I was already in the Git installation, did not replace)
libintl3.dll (from the Dependencies archive, from where iconv is downloaded from where)

Source: https://habr.com/ru/post/74839/


All Articles