如何处理Mac OS X上转换为unicode的Git文件名中的重音字符

时间:2012-08-15 11:03:46

标签: macos git unicode

在我的Git存储库中,重音文件为éíóúàèìòùãõ_800x600.jpg,但在进行克隆后,我无法执行pull,因为该文件显示为已修改:

$git clone [...]
done

$git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   "a\314\201e\314\201i\314\201o\314\201u\314\201a\314\200e\314\200i\314\200o\314\200u\314\200a\314\203o\314\203_800x600.jpg"

但是,我无法添加,删除,重置或存储文件。

我试过了:

$git add a\314\201e\314\201i\314\201o\314\201u\314\201a\314\200e\314\200i\314\200o\314\200u\314\200a\314\203o\314\203_800x600.jpg
fatal: pathspec 'a314201e314201i314201o314201u314201a314200e314200i314200o314200u314200a314203o314203_800x600.jpg' did not match any files

$git stash
No local changes to save

$git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   "a\314\201e\314\201i\314\201o\314\201u\314\201a\314\200e\314\200i\314\200o\314\200u\314\200a\314\203o\314\203_800x600.jpg"

如何处理转换为unicode的重音文件?

2 个答案:

答案 0 :(得分:13)

您需要在Mac上将core.precomposeunicode选项设置为true,然后再次克隆存储库。

git config --global core.precomposeunicode true

git config man page中所述,该选项与Mac OS中Unicode字符的特定分解有关:

  

此选项仅供Mac OS实现git使用。当core.precomposeunicode = true时,git将恢复Mac OS完成的文件名的unicode分解。在Mac OS与Linux或Windows之间共享存储库时,这非常有用。 (需要适用于Windows 1.7.10或更高版本的Git,或者在cygwin 1.7下使用git)。如果为false,则git处理文件名完全透明,git向后兼容旧版本的git。

手册页未指明的是,此选项对存储库没有追溯效果,只会在之后克隆的存储库中生效。

参考: Answer by Leo Koppelkamm in "Git and the Umlaut problem on Mac OS X"

答案 1 :(得分:1)