Knowledge
Change casing of file or directory in Git
#Git
Renaming already commited files or directories only for casing in Git will be ignored and will not show up as a change you can commit.
Published by Mark van Eijk on November 29, 2022 · 1 minute read
The problem
Sometimes you encouter the problem that a file or directory does not have the correct case-sensitive name it should have. So you rename the file and change its casing. After this change, Git does not show this and the renaming can't be commited.
So this is not enough:
mv File.php file.php
The reason
Since Git version 1.5.6 there is a setting core.ignorecase
that defines if casing should be ignored by default or not. To change the default setting to pick up casing changes, you can run inside the project:
git config core.ignorecase false
Or to disable it completely on your computer, you can set it globally using:
git config --global core.ignorecase false
The fix (without changing the config)
To fix this issue without changing any Git configurations: after you execute the mv
command line from before, you also need to tell git that the filename has changed. This can be done by using:
git mv --cached File.php file.php
Subscribe to our newsletter
Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!
Related articles
Removing tracked files in Git that should have been ignored
Renaming already commited files or directories only for casing in Git will be ignored and will not show up as a change you can commit.