"Go" git garbled solution Rollup

Source: Internet
Author: User
Tags i18n locale setting using git

git garbled solution sinks

    • 2012-11-04 Update: The official "ultimate" solution: MsysGit1.7.10 begins to save the file name using UTF-8 encoding.
    • 2011-10-24 Update: From an article that links to this article (I deeply agree with the article on how to get along with Windows patients), I found an "ultimate" solution, but I didn't test it.

I have been using git under Cygwin, supplemented by tortoisegit. The use of the problem, but today in the processing of a Chinese file name of the project, but there is a garbled file name.

The situation recurs
    • In a git project submitted with Cygwin Bash, all commits have been completed, but when viewed with tortoisegit, it is found that there are still files that are not committed, even if the files are still in the non-staged state. Then use Tortoisegit to submit;
    • Again, with the Git status under Cygwin, this time we found the uncommitted situation. Commit the command line again with git commit;
    • Go back to Tortoisegit to see, the problem has come again! At this time ready to return two times before the version, but because the file name garbled problem, can not be returned!
garbled reason

Search, found git file name, log garbled, is a common problem, which has the reason for encoding, there are cross-platform reasons. The main reason is that git in Windows system has different encoding for Chinese filenames.

The msysgit used in the Windows system uses the system encoding to save the file name, while git in Cygwin defaults to UTF-8 encoding to save the file name. If two software is operating on a repository at the same time, and all assume that the other person is using their own encoding to save the file, it will cause the file name encoding confusing and unrecognized.

This leads to, if the use of Tortoisegit (actually call Msysgit) submitted, then the Chinese file name is not a problem; Always use Cygwin submit, Chinese file name is no problem. But must not cross-use.

Set LANG, Lc_ctype, lc_all parameters to the same encoding, the problem remains.

Cygwin official website refers to the non-Latin language name of the problem, perhaps after the study can solve the bar: Chapter 2. Setting up Cygwin

There is also an article on Linux system coding: Locale settings and the difference between Lang, lc_all, language environment variables.

The Official Ultimate Solution

The official ultimate solution to this problem is to update to msysGit1.7.10 or later. After this version, Msysgit and git for Windows have adopted the UTF-8 encoding to save the file name, no longer garbled. Installation and use refer to this article: using Git, git gui, and Tortoisegit

Unfortunately, for a repository that was submitted with an older version of Msysgit, an upgrade to msysGit1.7.10 or higher would present a coding problem.

There are two articles that describe the solution to this problem:

    • Upgrade to Msysgit 1.7.10 (requires a FQ)
    • Upgrading to Msysgit 1.7.10 (or higher)

The following article, which is a legacy of history, can not be seen. If you want to know why, you may wish to view it.

Garbled scenarios and solutions garbled scenario 1

In Cygwin, when using git add to add a file to be submitted, if the file name is in Chinese, it will display 274\232\350\256\256\346\200\273\347\273\223.png garbled characters.

Solution:

At the bash prompt, enter:

git config--global core.quotepath false

If the Core.quotepath is set to False, the characters above 0x80 will not be quote. Chinese display is normal.

Garbled Scenario 2

In msysgit, use git log to display the submitted Chinese log garbled.

Solution:

Set the interface encoding of the Git GUI

git config --global gui.encoding utf-8

Set commit log commit with UTF-8 encoding to avoid garbled on the server and consistent with commits on Linux!

git config--global i18n.commitencoding utf-8

The UTF-8 encoding is converted to GBK encoding at git log, which resolves git log garbled in Msys bash.

git config--global i18n.logoutputencoding gbk

Allows git log to display Chinese correctly (with i18n.logoutputencoding = GBK), /etc/profile adding:

Export Lesscharset=utf-8
Garbled Scenario 3

In Msysgit's own bash, use the LS command to see the Chinese file name garbled. Cygwin does not have this problem.

Solution:

Use ls --show-control-chars the command to force a console character encoding to display the file name to view the Chinese file name.

For ease of use, you can edit /etc/git-completion.bash and add a new linealias ls="ls --show-control-chars"

The ultimate Solution

The ultimate solution is to modify the Git and Tortoisegit source implementation, a netizen has done this: let Windows git and tortoisegit support the Chinese file name/utf-8, You can also access this open-source Google project directly: Utf8-git-on-windows.

If you do not resist the command line, simply use Cygwin to submit the Git library. Because Cygwin is actually a simulator on the Windows platform, it runs in a completely simulated gnu/linux way, so git in Cygwin uses UTF-8 encoding to save Chinese.

another "ultimate" solution (from)(This scenario is no longer recommended after msysGit1.7.10)

When working with Git, change the locale setting to Chinese GBK. After that, you can do git-related operations.

Consistency with windows in the terminal

Lc_all=ZH_CN. GBKLANGset charactor encoding-GBK  

Switch back to Linux default

Lc_all=en_us.utf8LANGset charactor encoding-Unicode(utf-8)    

Change the encoding of the file name

You can also switch file names between UTF8 and GBK if the bad results have been caused by garbled characters. Modify the displayed (decoded) effect as you did above.

CONVMV <filename> F utf8-t GBK

Exception: CONVMV is not valid on FAT32 's USB drive, it is estimated that FAT32 does not allow illegal encoding.

This article refers to links
    • Fix git Chinese garbled, use Tortoisemerge implement Diff/merge
    • Msysgit garbled and cross-platform version management
    • Git Chinese file name, directory name garbled should be how to solve?

Set the Git install directory toC:\Git

1. Using the git add command to add files with Chinese characters in the file name 1.1 garbled like:
    \316\304\261\276\316\304\265\265.txt
1.2 Solution:

Edit the C:\Git\etc\inputrc corresponding line in the file, look for the following 2 lines, and modify their values.
Original:

        set output-meta off    set convert-meta on

Switch

        set output-meta on    set convert-meta off
2. When using git log to view log information containing Chinese, 2.1 garbled is similar:
    <E4><BF><AE><E6><94><B9><E6><96><87><E6><9C><AC><E6><96><87><E6><A1><A3>
2.2 Solution:

At the bash prompt, enter:

    git config --global i18n.commitencoding utf-8    git config --global i18n.logoutputencoding gbk

Note: You can avoid garbled Linux servers by using UTF-8 encoding when setting commit commits, and set git log utf-8 encoding to GBK encoding at execution time to solve garbled problems.
C:\Git\etc\profileto edit the file, add the following line:

    export LESSCHARSET=utf-8

Note: To enable git log to display Chinese correctly (requires mates: i18n.logoutputencoding gbk )

3. Use the LS command to view the file name containing Chinese characters garbled when 3.1 garbled similar:
        ????.txt    ???????.md
3.2 Solution:

Use the LS--show-control-chars command to force the display of file names using console character encoding to view Chinese file names.
For ease of use, you can edit the C:\Git\etc\git-completion.bash file and add the following line:

    alias ls="ls --show-control-chars"
4. When viewing UTF-8 encoded text files in the Git GUI, 4.1 garbled characters are similar:
    锘夸腑鏂囨枃妗£
4.2 Solution:

At the bash prompt, enter:

    git config --global gui.encoding utf-8

Note: Through the above settings, UTF-8 encoded text files can be viewed normally, but GBK encoded files will be garbled, so still did not fundamentally solve the problem.

One possible way is to unify the encoding of all text files to UTF-8 or GBK, and then set the corresponding gui.encoding parameters to utf-8 or gbk .

Reference Links:

1190000000578037

Http://zengrong.net/post/1249.htm

"Go" git garbled solution Rollup

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.