I wrote this script and ran it on OSX 10.8 Mountain Lion, on the default case-insensitive HFS filesystem.
#!/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
When the script was done, it failed on the last line, when it should have succeeded:
+ 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 showed this:
$ 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")
We can get the file back at that point with git checkout File
, but it's very easy at that point to accidentally commit the deletion.
We've been renaming quite a few files lately, fixing their capitalization, and this has bit our team a lot. Is there a git setting or best practice we can use to workaround this problem? (For now, we're just telling everybody to be extra extra careful.)