今天我在Mac和OS上发现了一个Git的bug。
例如,我将提交一个名称为überschrift.txt的文件,其开头为德语特殊字符µ。在命令git status
中,我得到以下输出。
Users-iMac: user$ git status
On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# "U\314\210berschrift.txt"
nothing added to commit but untracked files present (use "git add" to track)
似乎Git 1.7.2在Mac和OS上的德语特殊字符有问题。有没有解决方案让Git读取正确的文件名?
发布于 2013-03-22 01:06:38
在mac上启用core.precomposeunicode
git config --global core.precomposeunicode true
要实现这一点,您需要至少安装Git 1.8.2。
Mountain Lion的发行版是1.7.5。要获得更新的git,可以使用git-osx-installer或homebrew (需要Xcode)。
就这样。
发布于 2016-12-21 01:44:44
以下放入~/.gitconfig中的内容在10.12.1 Sierra上适用于UTF-8名称:
precomposeunicode = true
quotepath = false
需要第一个选项,这样git才能“理解”UTF-8,第二个选项才不会转义字符。
发布于 2011-09-06 23:04:32
要使git add file
在Mac上与文件名中的变音一起工作,可以使用iconv
将文件路径字符串从合成的UTF-8转换为规范分解的UTF-8。
# test case
mkdir testproject
cd testproject
git --version # git version 1.7.6.1
locale charmap # UTF-8
git init
file=$'\303\234berschrift.txt' # composed UTF-8 (Linux-compatible)
touch "$file"
echo 'Hello, world!' > "$file"
# convert composed into canonically decomposed UTF-8
# cf. http://codesnippets.joyent.com/posts/show/12251
# printf '%s' "$file" | iconv -f utf-8 -t utf-8-mac | LC_ALL=C vis -fotc
#git add "$file"
git add "$(printf '%s' "$file" | iconv -f utf-8 -t utf-8-mac)"
git commit -a -m 'This is my commit message!'
git show
git status
git ls-files '*'
git ls-files -z '*' | tr '\0' '\n'
touch $'caf\303\251 1' $'caf\303\251 2' $'caf\303\251 3'
git ls-files --other '*'
git ls-files -z --other '*' | tr '\0' '\n'
https://stackoverflow.com/questions/5581857
复制相似问题