简体   繁体   中英

How to change chinese filename from gbk to utf-8 in windows git-bash?

I found if I commit a filename with Chinese character to some git repo, I cannot pull that repo in macos again:

$ git pull

...

error: unable to create file ???: Illegal byte sequence

Google told me that I should change the filenames from gbk to utf-8 on Linux. But I only have windows/macos machines.

Can I change the filenames from gbk to utf-8 in git-bash for windows? Thanks!

Btw, these filename have special meaning and I cannot simply change those name to English words. I must keep those names in another encoding.

TL;DR

In Git Bash on Windows, you can refer to file names by their octal byte sequences with the syntax $'\303\251' or the hex byte sequences with the syntax $'\xc3\x83'

Details

I don't have a machine setup to work with gbk, but I have tested, and on Windows, Git Bash will let you refer to file names by their byte sequences.

Partial reproduction: I have file called é (utf8 byte sequence in octal: \303\251 ) and I want to rename it to ê (utf8 byte sequence in octal: \303\252 ).

To do that rename operation, this worked for me in Git Bash on Windows:

git mv $'\303\251' $'\303\252'

So... if you are able to do a successful checkout of your gbk file on Windows, you should be able to rename it using that technique.

To find out the octal sequence representing names already in Git, by the way, git log --stat , git show <commit> , etc, display the filename in those octal escape sequences for me.I don't know if that's always the case, though. ls | od ls | od might also help.

Also, the hex syntax also works: $'\xc3\x83' .

Note: those syntaxes are not handled by Git, but rather by Bash itself, and should work on the bash prompt on any OS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM