The best answers to the question “How do I commit case-sensitive only filename changes in Git?” in the category Dev.
I have changed a few files name by de-capitalize the first letter, as in
name.jpg. Git does not recognize this changes and I had to delete the files and upload them again. Is there a way that Git can be case-sensitive when checking for changes in file names? I have not made any changes to the file itself.
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).
git config documentation:
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
makefilewhen git expects
Makefile, git will assume it is really the same file, and continue to remember it as
The default is false, except git-clone(1) or git-init(1) will probe and set
core.ignorecasetrue if appropriate when the repository is created.
The two most popular operating systems that have case-insensitive file systems that I know of are
- OS X
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.)
This is what I did on OS X:
git mv File file.tmp git mv file.tmp file
Two steps because otherwise I got a “file exists” error. Perhaps it can be done in one step by adding
--cached or such.
Using SourceTree I was able to do this all from the UI
- Stage that file
- Now rename
- 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