110

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?

nowox
  • 25,978
  • 39
  • 143
  • 293
JAkk
  • 1,326
  • 2
  • 10
  • 12

6 Answers6

126

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.

Dave Everitt
  • 17,193
  • 6
  • 67
  • 97
manojlds
  • 290,304
  • 63
  • 469
  • 417
  • 92
    This is the correct answer imo. For future me, use `git config --unset-all core.ignorecase && git config --system core.ignorecase false` with sudo. – Markus Hedlund Jun 28 '12 at 11:28
  • 2
    @Znarkus On OS X, your code was EXACTLY what I needed. Thank you! – James Brown Sep 13 '12 at 02:26
  • 3
    ditto to James, @Znarkus has identified the fix for this problem on OS X, Thanks! – Craig Nakamoto Oct 26 '12 at 17:39
  • 1
    @Znarkus Works on Windows too. Beautiful. – orlade Sep 25 '13 at 16:25
  • 9
    @Znarkus, the problem with doing that on OSX is that when you rename a file through the finder, and only change the case, git will see the renamed version as a completely new file, but it doesn't generate a corresponding "delete" action for the old version of the file. So if you commit and push to github, github will have both the old-named and the newly-named file, but your local system will just have the new file, and git will be none the wiser. – ivanreese Jun 05 '14 at 18:39
  • 2
    @spiralganglion For web dev on OSX I can really recommend [creating a case sensitive partition](http://stackoverflow.com/a/9596248/138023) and then mount it as your www directory. – Markus Hedlund Jun 06 '14 at 09:41
  • i went to very great lengths and weird things were done only get git go around git's insensitivity to letters only to find all i had to do was tell git to mind the case...there should be watch out list for windows users. – Muhammad Umer Jul 17 '14 at 21:04
78

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: git mv and only change case of directory

Community
  • 1
  • 1
Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • looks like this was right (except that I was changing from capital letters to downcase) – JAkk Dec 12 '11 at 22:30
  • I peeked into it, as long as I'm used to cygwin, it is just more comfortably to use cygwin - thanks for the hint – JAkk Dec 13 '11 at 05:02
  • You can just do `git mv file.txt File.txt`. Not sure if this is a new git feature. – Phil Dec 08 '16 at 18:51
24

This is far easier:

git mv Electronics electronics -f
git commit -m "That was easy!"
Arnoud
  • 431
  • 3
  • 7
24
git config --system core.ignorecase false
Cemo
  • 5,370
  • 10
  • 50
  • 82
0

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
Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170
0

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.