Luc*_*aka 68 versioning git macos
今天我在Mac OS X上发现了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 X上存在德语特殊字符的问题.是否有解决方案让Git读取文件名正确?
chi*_*ken 87
在mac上启用core.precomposeunicode
git config --global core.precomposeunicode true
为此,您需要至少拥有Git 1.8.2.
山狮以1.7.5发货.要获得更新的git,请使用git-osx-installer或homebrew(需要Xcode).
而已.
Yuj*_*uji 31
原因是文件系统如何存储文件名的不同实现.
在Unicode中,Ü可以用两种方式表示,一种是由Ü单独表示,另一种是由U +"组合变音字符".Unicode字符串可以包含两种形式,但由于两者都令人困惑,因此文件系统通过将每个umlauted-U设置为Ü或U +"组合变音字符"来规范化unicode字符串.
Linux使用前一种方法,称为Normal-Form-Composed(或NFC),Mac OS X使用后一种方法,称为Normal-Form-Decomposed(NFD).
显然Git不关心这一点,只是使用文件名的字节序列,这会导致你遇到的问题.
邮件列表线程Git,Mac OS X和德语特殊字符都有一个补丁,以便Git在规范化后比较文件名.
以下放在〜/ .gitconfig中的10.12.1 Sierra适用于UTF-8名称:
precomposeunicode = true
quotepath = false
需要第一个选项,以便git'理解'UTF-8和第二个选项,以便它不会转义字符.
小智 5
要git add file在Mac OS X上使用文件名中的变音符号,您可以使用将文件路径字符串从组合转换为规范分解的UTF-8 iconv.
# 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'
| 归档时间: | 
 | 
| 查看次数: | 15676 次 | 
| 最近记录: |