abhijeetviswa
abhijeetviswa

Reputation: 113

Making git case-insensitive to source code?

I would like to make git be case-insensitive to source code. Is there anyway to achieve this? (No, I don't want it to ignore case change in filepath.)

Upvotes: 0

Views: 864

Answers (2)

Jan Hudec
Jan Hudec

Reputation: 76346

Well, sure, there is. If you want to hang yourself, git will gladly provide you enough rope2 a hook.1

Git itself tracks content and does not care about what the content is. Lower and uppercase letters are encoded as different bytes and that's all git knows.

However git is very extensible. You can tell it to use custom filter when reading files from disk, when writing them to disk, when calculating differences between them and when merging them.

If you want to make it case-preserving and just ignore case in diff and merge, you need to implement custom diff and merge drivers. Look up diff in gitattributes(5). If you want to normalize everything to upper or lowercase, you need to implement read and write filters (called "clean" and "smudge"). Look up filter in gitattributes(5). And than you have to apply it to appropriate files using the gitattributes mechanism.


1 That is, I really think it's a bad idea. Most programming languages are case-sensitive and for the ones that are not it would be much easier to just stick to one case (usually lower) yourself. But maybe under some circumstances it might be the best of bad options.

2 You have to provide the rope (the filters to do the case conversion) yourself.

Upvotes: 3

Munim
Munim

Reputation: 6520

Git isn't case insensitive to source code, because source code isn't case insenstive. Changing the case of your code changes the meaning of the code. var abc and var ABC are two different variable declarations.

What you should do is to follow a proper coding style which adopts a case pattern to follow, and stick to it.

Upvotes: -1

Related Questions