我编写了这个脚本并在 OSX 10.8 Mountain Lion 上运行它,在默认的不区分大小写的 HFS 文件系统上。
#!/bin/sh -x
# create git repo
rm -rf caps
git init caps
cd caps
# commit empty file called "file"
touch file
git add .
git commit -am "initial commit"
# create branch called "branch"
git branch branch
# rename "file" to "File"
# using --force per http://stackoverflow.com/questions/6899582
git mv --force file File
git commit -am "renamed capital"
# switch to branch, make a non-conflicting commit
git checkout branch
touch newfile
git add .
git commit -am "branch commit"
# merge master into branch, commit merge
git merge --commit --no-edit master
# but where's the renamed File?
more File
脚本完成后,它在最后一行失败了,而它本应成功:
+ git merge --commit --no-edit master
Removing file
Merge made by the 'recursive' strategy.
file => File | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename file => File (100%)
+ more File
File: No such file or directory
git status 显示了这一点:
$ git status
# On branch branch
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: File
#
no changes added to commit (use "git add" and/or "git commit -a")
我们可以在那个时候用 取回文件git checkout File
,但是在那个时候很容易意外地提交删除。
我们最近一直在重命名很多文件,修复它们的大小写,这对我们的团队造成了很大的伤害。有没有我们可以用来解决这个问题的 git 设置或最佳实践?(现在,我们只是告诉大家要格外小心。)