I am trying to rename a file to have different capitalization from what it had before:
git mv src/collision/b2AABB.js src/collision/B2AABB.js
fatal: destinat
Starting Git 2.0.1 (June 25th, 2014), a git mv
will just work on a case insensitive OS.
See commit baa37bf by David Turner (dturner-tw).
mv
: allow renaming to fix case on case insensitive filesystems"git mv hello.txt Hello.txt
" on a case insensitive filesystem always triggers "destination already exists
" error, because these two names refer to the same path from the filesystem's point of view and requires the user to give "--force
" when correcting the case of the path recorded in the index and in the next commit.
Detect this case and allow it without requiring "
--force
".
git mv hello.txt Hello.txt
just works (no --force
required anymore).
The other alternative is:
git config --global core.ignorecase false
And rename the file directly; git add and commit.
This Python snippet will git mv --force
all files in a directory to be lowercase. For example, foo/Bar.js will become foo/bar.js via git mv foo/Bar.js foo/bar.js --force
.
Modify it to your liking. I just figured I'd share :)
import os
import re
searchDir = 'c:/someRepo'
exclude = ['.git', 'node_modules','bin']
os.chdir(searchDir)
for root, dirs, files in os.walk(searchDir):
dirs[:] = [d for d in dirs if d not in exclude]
for f in files:
if re.match(r'[A-Z]', f):
fullPath = os.path.join(root, f)
fullPathLower = os.path.join(root, f[0].lower() + f[1:])
command = 'git mv --force ' + fullPath + ' ' + fullPathLower
print(command)
os.system(command)
File names under OS X are not case sensitive (by default). This is more of an OS problem than a Git problem. If you remove and readd the file, you should get what you want, or rename it to something else and then rename it back.