0

I'm learning git so please forgive me if this has been answered before. I added a file README.txt to the working directory. git status tells me that this is the only untracked file. I then ran git add readme.txt. Running git status now tells me once again that README.txt is the only untracked file. However, if I then run git add README.txt it now shows up as a new file. Does this mean that git is adding a snapshot of the file readme.txt which doesn't exist? I don't understand as I thought that git was case insensitive.

REAL O G
  • 693
  • 7
  • 23

2 Answers2

2

I thought that git was case insensitive.

Not really. There's a config setting core.ignorecase which is normally set to true in Windows; the docs say

If true, this option enables various workarounds to enable Git to work better on filesystems that are not case sensitive

But that's a long way from saying Git is case-insensitive. I reproduced what you did and I think you found a bug.

$ git checkout -b test 
Switched to a new branch 'test'

$ echo hello > README.txt

$ git status 
On branch test 
Untracked files:   (use "git add <file>..." to include in what will be committed)

        README.txt

nothing added to commit but untracked files present (use "git add" to track)

$ git add readme.txt

$ git status 
On branch test 
Untracked files:   (use "git add <file>..." to include in what will be committed)

        README.txt

nothing added to commit but untracked files present (use "git add" to track)

$ git diff --cached

$

One of two things should have happened: either Git should have complained that readme.txt didn't exist when I (and you) added it, or it should have added the contents of README.txt to the cache. It didn't do either of those things: no error from git add and no results listed by git diff --cached.

So my advice is treat Git commands as case-sensitive even when core.ignorecase is set to true.

gatkin
  • 1,902
  • 12
  • 12
1

You have NTFS underneath which is case insensitive. So if git asks if "README.txt" still exists, it is told "yes" even if you now have "readme.txt".

I would suggest telling git to forget completely about "README.txt" with

git rm --cached README.txt

and then add readme.txt again.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • Not sure I follow. I understand windows ntfs is case insensitive. Are you saying that I need to input commands into git using case sensitivity? If i tell git to forget "README.txt", and then use `git add readme.txt` wouldn't I be in the same situation where the actual filename in the working directory is "README.txt" but git thinks it's "readme.txt". The actual filename is "README.txt" but entered it into git as "readme.txt". – REAL O G May 20 '15 at 20:31
  • Then reverse the instructions so it is "readme.txt" that is forgotten. This happens on OS X too which has HFS. If you want git to work its best then use Linux (or a good IDE). – Thorbjørn Ravn Andersen May 20 '15 at 21:47
  • I don't know if it could help be you can configure git to be case insensitive : http://stackoverflow.com/questions/52950/how-to-make-git-ignore-changes-in-case – Philippe May 20 '15 at 21:50