Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git on Windows capitalized file names on origin, lower case locally

Tags:

git

windows

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?

like image 881
bladekp Avatar asked Dec 15 '17 11:12

bladekp


People also ask

Is git case sensitive for file names?

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.

Is git case sensitive for folder names?

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.

How do you capitalize all file names?

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.


1 Answers

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.

like image 92
poke Avatar answered Oct 17 '22 12:10

poke