Due to the per-developer naming convention I had to rename a bunch of files of a laravel app, eg. supplyController.php to SupplyContoller.php. The files are created on windows, so the filesys is case-insensitive, but the production VPS has debian/case-sensitive, so it’s important to have the right naming to deploy.
The changes are already committed and pushed, and afaik it’s the normal behavior, the git repo contains the lower-case version of files. Beside git mv for each file, is there any better solution recommended to correct the repo?
2
Answers
git mv
is indeed your best option.What you may be interested too is probably a way to modify, in a bulk way, lot of different files?
If that is the case, then your real question is maybe: how to generate a loop that will perform the various
git mv
in an consistent way?E.g.:
I guess this would be easier on a non-Windows OS for two reasons: shells and file system really being case-insensitive (which they tend to be outside of Windows).
While
git mv
will work, it does require you to provide a mapping fromfileName
toFileName
, 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):
The trick here is simple: In a case-insensitive configuration, git will understand that the worktree file
MyFile
is the same as the index entrymyFile
– 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.)