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

2024-02-27

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

$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"

尽管如此,我仍无法添加、删除、重置或隐藏该文件。

I tried:

$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 的重音文件?


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

git config --global core.precomposeunicode true

如中所述git 配置手册页 https://www.kernel.org/pub/software/scm/git/docs/git-config.html,该选项与 Mac OS 中 Unicode 字符的特定分解有关:

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

手册页没有指出的是,此选项对存储库没有追溯作用,它仅在之后克隆的存储库中生效。

参考:Leo Koppelkamm 在“Git and the Umlaut Problem on Mac OS X”中的回答 https://stackoverflow.com/a/15553796/207968

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐