Pure transfer: https://segmentfault.com/a/1190000000578037
1. When using the git add command to add a file whose file name contains Chinese characters
1.1 garbled characters are similar:
\316\304\261\276\316\304\265\265.txt
1.2 Solution:
Edit C:\Git\etc\inputrc
the corresponding line in the file, find the following 2 lines, and modify their values,
originally:
set output-meta off
set convert-meta on
Change it to:
set output-meta on
set convert-meta off
2. When using git log to view log information containing Chinese
2.1 The garbled characters are similar:
<E4><BF><AE><E6><94><B9><E6><96><87><E6><9C><AC><E6><96><87><E6><A1><A3>
2.2 Solution:
Enter at the Bash prompt:
git config --global i18n.commitencoding utf-8
git config --global i18n.logoutputencoding gbk
Note: Set commit to use utf-8 encoding to avoid garbled characters on the Linux server; at the same time, set git log
to convert utf-8 encoding to gbk encoding during execution to solve the problem of garbled characters.
Edit C:\Git\etc\profile
the file and add the following line:
export LESSCHARSET=utf-8
Note: so that git log can display Chinese normally (requires cooperation: i18n.logoutputencoding gbk
)
3. Use the ls command to view garbled file names containing Chinese characters
3.1 garbled characters are similar:
????.txt
???????.md
3.2 Solutions:
Use the ls --show-control-chars command to force the use of console character encoding to display the file name, and you can view the Chinese file name.
For convenience, you can edit the C:Gitetcgit-completion.bash file and add the following line:
alias ls="ls --show-control-chars"
4. When viewing UTF-8 encoded text files in Git Gui
4.1 garbled characters are similar:
锘夸腑鏂囨枃妗£
4.2 Solution:
Enter at the Bash prompt:
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 the problem is still not fundamentally solved.
One of the feasible methods is: unify the encoding of all text files as UTF-8 or GBK, and then set the corresponding gui.encoding
parameters to utf-8
or gbk
.
Note: This article refers to the success of others and is not completely original.
Passed the personal test and solved the problem of garbled code viewing history