We are forced to work on Windows at work, and I have lets say problem, strange situation. We have github repository, inside which we have one directory with name Something
(with capitalized first letter 'S'), but in my local I see this directory with name something
(note lower case 's'), git status shows that working directory is clean, even if I change this directory locally to, for example SoMeThInG
git says that nothing changed. I suspect that Windows is here a problem, as it is case insensitive. Is there possibility to change this directory name from Windows level? Or maybe how to force git bash to be case sensitive?
Update
I've changed that files from mine virtual fedora, but this is just a workaround, the question remains unanswered, how to do it properly on Windows?
The Windows and macOS file systems are case-insensitive (but case-preserving) by default. Most Linux filesystems are case-sensitive. Git was built originally to be the Linux kernel's version control system, so unsurprisingly, it's case-sensitive.
Git is a unix based code. its is case sensitive so it will allow you to have the same name in different cases, and as you except windows will not be tolerated for this. There is nothing you can do about it beside renaming your folders.
Capitalize the first letter of each word in a file name. This is called “CamelCase.” It is an efficient way to differentiate words but it can be harder to read. If the file name contains a capitalized acronym, it should appear in capitals and the first letter of the following word should also be capitalized.
On case-insensitive file systems, Git will not detect changes just in casing. However, when committing files, the actual casing is still being reflected in the way it was added to the index.
So a git add foo
and git add FOO
will both work for a file that is named foo
in any kind of casing (e.g. FoO
or fOo
), but each command will actually stage that exact name into the repository. So git add foo
will make the name be case-sensitive foo
and git add FOO
will make the name case-sensitive FOO
.
That’s why you should try to always use your command line auto completion for file names, so you don’t accidentally add files with a different casing than they actually are. Or use commands that stage the files automatically, e.g. git add .
, since that will also use the actual casing.
However, since Git will not detect casing changes, once a file has been added with a particular casing, that casing will be used until you explicitly change it. That’s why it’s possible to have files in a folder foo/bar
and FOO/baz
that are both physically in the same location on your file system, but are represented using incompatible paths inside of Git. So you should be careful here.
That all being said, you can fix the casing later. But to do that, you need to make the change using Git instead of the file system, as Git is case sensitive while the file system isn’t. So commands like git mv
will work. Same as a combination of git rm --cached
and git add
.
For example, to fix the above situation of the foo
/FOO
directory, one could do (assuming the correct name of the folder should be Foo
):
git mv foo/bar Foo/bar
# or
git rm --cached FOO/baz
git add Foo/baz
You can also fix the casing for every file by removing everything from the index, and then adding it back:
git rm --cached -r .
git add .
That should stage all renames to the correct file casing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With