Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

macos - How to handle Asian characters in file names in Git on OS X

I'm on US-English OS X 10.6.4 and try to store files with Asian characters in its name in a Git repository.

OK, let's create such a file in a Git working tree:

$ touch どうもありがとうミスターロボット.txt

Git is showing it as octal-escaped UTF-8 form:

$ git version
git version 1.7.3.1
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   "343201250343202231343201206343202202343201202343202212343201213343202231343201250343201206343203237343202271343202277343203274343203255343203233343202231343203203343203210.txt"
nothing added to commit but untracked files present (use "git add" to track)

Unfortunately, I'm not able to add it to the Git repository:

$ git add どうもありがとうミスターロボット.txt
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   "343201250343202231343201206343202202343201202343202212343201213343202231343201250343201206343203237343202271343202277343203274343203255343203233343202231343203203343203210.txt"
nothing added to commit but untracked files present (use "git add" to track)

Git simply ignored this file.

Using wildcards work:

$ git add *.txt
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   "343201250343202231343201206343202202343201202343202212343201213343202231343201250343201206343203237343202271343202277343203274343203255343203233343202231343203203343203210.txt"
#

but I want to invoke the Git command from an application for a specific file name. I don't have the option to invent wildcard patterns which match exactly this file, but no one else.

Is this a known bug of Git or me not using Git correctly?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Git quotes any non-ascii character by default, not only asian ones. There's an option to disable this quoting behaviour.

You can disable it using the following command:

git config --global core.quotepath false

Or, alternatively, by adding the following snippet to your git config file ($HOME/.gitconfig usually)

[core]
    quotepath = false

After this, git should show your filenames exactly as they are.

As to your other problem, git not adding a file with asian characters, I can only guess that it has to do with the encoding that git uses is not the same as the encoding your terminal uses. I hope someone else can jump in and explain that bit.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...