How do I commit case-sensitive only filename changes in Git? How do I commit case-sensitive only filename changes in Git? git git

How do I commit case-sensitive only filename changes in Git?


As long as you're just renaming a file, and not a folder, you can just use git mv:

git mv -f yOuRfIlEnAmE yourfilename

(As of a change in Git 2.0.1, the -f flag in the incantation above is superfluous, but it was needed in older Git versions.)


Git has a configuration setting that tells it whether to expect a case-sensitive or insensitive file system: core.ignorecase. To tell Git to be case-senstive, simply set this setting to false. (Be careful if you have already pushed the files, then you should first move them given the other answers).

git config core.ignorecase false

Note that setting this option to false on a case-insensitive file system is generally a bad idea. Doing so will lead to weird errors. For example, renaming a file in a way that only changes letter case will cause git to report spurious conflicts or create duplicate files(from Mark Amery's comment).

Documentation

From the git config documentation:

core.ignorecase

If true, this option enables various workarounds to enable git to work better on filesystems that are not case sensitive, like FAT. For example, if a directory listing finds makefile when git expects Makefile, git will assume it is really the same file, and continue to remember it as Makefile.

The default is false, except git-clone(1) or git-init(1) will probe and set core.ignorecase true if appropriate when the repository is created.

Case-insensitive file-systems

The two most popular operating systems that have case-insensitive file systems that I know of are

  • Windows
  • OS X


Using SourceTree I was able to do this all from the UI

  1. Rename FILE.ext to whatever.ext
  2. Stage that file
  3. Now rename whatever.ext to file.ext
  4. Stage that file again

It's a bit tedious, but if you only need to do it to a few files it's pretty quick