1

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?

gramgram
  • 565
  • 3
  • 18
  • Does this answer your question? [Changing capitalization of filenames in Git](https://stackoverflow.com/questions/10523849/changing-capitalization-of-filenames-in-git) – phd Feb 18 '20 at 13:19
  • https://stackoverflow.com/search?q=%5Bgit%5D+rename+case-sensitive – phd Feb 18 '20 at 13:19
  • Yes, partially, but a bulk solution would be fine. As i see, not a straightforward automation. – gramgram Feb 18 '20 at 13:23
  • 1
    There is no generic universal way, sorry. You have to write something yourself. – phd Feb 18 '20 at 13:29

2 Answers2

3

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.)

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
  • Thanks, works fine if it's not a problem loosing history for the renamed files. Tried with ignorecas true/false, git version 2.14.1.win. Ended up using git mv for the few dozen of renamed files. – gramgram Feb 18 '20 at 19:54
  • @gramgram - Not sure what you mean about losing history. The approach I outlined does not change history in any way. – Mark Adelsberger Feb 18 '20 at 21:18
0

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.:

$ git mv controllers/abccontroller.php controllers/AbcController.php
$ git mv controllers/defcontroller.php controllers/DefController.php
$ git mv controllers/ghicontroller.php controllers/GhiController.php
$ git mv controllers/jklcontroller.php controllers/JklController.php
...

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).

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Patrick Allaert
  • 1,751
  • 18
  • 44
  • Edited your last sentence. It's the _file system_, not the operating system, that decides whether file names are case insensitive. – Peter O. Jul 12 '20 at 18:53