1800 INFORMATION
1800 INFORMATION

Reputation: 135375

How to make git ignore changes in case?

I'm not too sure what is going on here, but sometimes a particular file in my repository will change the case of its name. e.g.,:

before: File.h

after: file.h

I don't really care why this is happening, but this causes git to think it is a new file, and then I have to go and change the file name back. Can you just make git ignore case changes?

[edit] I suspect it is Visual Studio doing something weird with that particular file, because it seems to happen most often when I open and save it after changes. I don't have any way to fix bugs in VS however, but git should be a bit more capable I hope.

Upvotes: 153

Views: 155515

Answers (7)

MarkB
MarkB

Reputation: 5377

Since version 1.5.6 there is an ignorecase option available in the [core] section of .git/config

e.g. add ignorecase = true

To change it for just one repo, from that folder run:

git config core.ignorecase true

To change it globally:

git config --global core.ignorecase true

Upvotes: 250

DaveWilliamson
DaveWilliamson

Reputation: 370

Possible finding (As of VS 2019 16.11.26): If the path to the project file in the SLN file is a different case from everywhere else this might also trigger the condition. We found this by right click on the Project in the solution and choose Open Folder in File Explorer. We noticed the path at top of file explorer was the case in the SLN file and not what was in the file system if you just opened this path on your own via File Explorer. So we suspect this path in the SLN was being passed to some git operations and the other version of the path was passed at other git operation times. Or the git operations have not received the core.ignorecase love.

Upvotes: 0

Mario
Mario

Reputation: 51

  1. From the console: git config core.ignorecase true
  2. Change file name capitalisation
  3. Commit
  4. From the console: git config core.ignorecase false

Step 4 fixed problems checking out branches with a different capitalisation.

Upvotes: 3

FoxDeploy
FoxDeploy

Reputation: 13547

To force git to recognize the change of casing to a file, you can run this command.

  1. Change the File casing however you like
  2. git mv -f mynewapp.sln MyNewApp.sln

The previous command seems to be deprecated now.

Upvotes: 8

Andrew Arnott
Andrew Arnott

Reputation: 81811

You can force git to rename the file in a case-only way with this command:

git mv --cached name.txt NAME.TXT

Note this doesn't change the case of the file in your checked out copy on a Windows partition, but git records the casing change and you can commit that change. Future checkouts will use the new casing.

Upvotes: 21

akauppi
akauppi

Reputation: 18056

The situation described in the question is now re-occuring with Mac OS X, git version >= 1.7.4 (I think). The cure is to set your ignorecase=false and rename the lowercased files (that git changed that way, not Visual Studio) back to their UsualCase by hand (i.e. 'mv myname MyName').

More info here.

Upvotes: 6

John C
John C

Reputation: 313

In git version 1.6.1.9 for windows I found that "ignorecase=true' in config was already set by default.

Upvotes: 15

Related Questions