Is git not case sensitive?

GitVersion ControlCase Sensitive

Git Problem Overview


In the first commitment of my partial called _Electronics it was written beginning with a capital letters, then I changed it to _electronics.

Git under cygwin ignored the case after commiting the new name, so I changed the name by hand in the target repo.

Now it sometimes changes the commited _electronics partial to _Electronics.

What have I done wrong?

Git Solutions


Solution 1 - Git

It is going to depend on the core.ignorecase configuration value, which is set to false in case-sensitive filesystems and true in msysgit on Windows.

> 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.

More detail in this reply to Changing capitalization of filenames in Git.

Solution 2 - Git

It will be seen as 2 different things but will cause you issues on a non-case-sensitive system. If this is the case, ensure you are tab-completing any paths or file names. Further, to change the name of something in just the case, do this:

mv file.txt temp.txt
git add -A
git commit -m "renaming..."
mv temp.txt File.txt
git add -A
git commit --amend -m "Renamed file.txt to File.txt"

This is an explicit way of making changes committing them, then collapsing the commits. A shorter way to do it is to manipulate the index and working folder all in one:

git mv file.txt temp.txt
git mv temp.txt File.txt
git commit -m "Renamed file.txt to File.txt"

This is related to adjusting directory names as well: https://stackoverflow.com/questions/3011625/git-mv-and-only-change-case-of-directory/3011723#3011723

Solution 3 - Git

This is far easier:

git mv Electronics electronics -f
git commit -m "That was easy!"

Solution 4 - Git

git config --system core.ignorecase false

Solution 5 - Git

In my scenario I had two folders tests and Tests which showed as two separate folders in Github but a single Tests folder in Windows. My aim was to combine them both into tests.

I used the following approach:

  1. Create a new folder temp
  2. Copy all content from Tests to temp
  3. Delete Tests
  4. execute git rm Tests -r
  5. Rename temp to tests

Solution 6 - Git

I have tried to solve the issue and it was successful on Windows10

Lets suppose there are two folders on bitbucket TEST and test but when I clone repo on disk it creates only TEST and I want to keep test as single folder on git which contains all files.

I will need to execute following commands on command line git mv TEST test1 -f git mv text1 test -f git commit -m "renaming..." git push

Now you will see that folder hierarchy is corrected on bitbucket.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJAkkView Question on Stackoverflow
Solution 1 - GitmanojldsView Answer on Stackoverflow
Solution 2 - GitAdam DymitrukView Answer on Stackoverflow
Solution 3 - GitArnoudView Answer on Stackoverflow
Solution 4 - GitCemoView Answer on Stackoverflow
Solution 5 - GitJeroen VannevelView Answer on Stackoverflow
Solution 6 - GitNitesh GoyalView Answer on Stackoverflow