While git mv
will work, it does require you to provide a mapping from fileName
to FileName
, which can be tedious - and most attempts to automate this would be error-prone.
On the other hand, if you have a clone whose worktree has the desired capitalization, then you can rebuild the index from that worktree. (It may seem risky to wipe the index in this way; but even if something went wrong, you could easily rebuild the index with reset
or, in the absolute worst case, restore from the origin - that being part of the point of distributed source control.)
So with the repo in a clean state (no untracked files that aren't ignored, no unstaged changes, and preferably also no staged-but-uncommitted changes):
git rm --cached -r -- :/:
git add -- :/:
The trick here is simple: In a case-insensitive configuration, git will understand that the worktree file MyFile
is the same as the index entry myFile
- so just doing an add doesn't change the name in the index. But if the index has no matching entry, then the filename case will match what's currently in the worktree.
(It seems like maybe you're saying that's not the behavior you expect; I just re-tested, and at least as of 2.25.0.windows.1 that is the behavior I see. I don't remember any version that behaved differently.)