Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform case insensitive diff in Git

git diff does not support a case-insensitive comparison of files. Google shows a very few people asking for that feature, and that too only in combination with some other git diff switch, like with -G or with --color-words.

I don't care for other switches, as long as git diff can show me the case-insensitive diff.

Since I didn't see any specific question towards that, and since I found a solution after an hour researching this problem, I am adding this question and the answer.

like image 340
Gurjeet Singh Avatar asked Jun 29 '13 12:06

Gurjeet Singh


1 Answers

The solution is to use git difftool. With the following config command, I can add a custom diff tool called idiff for Git to use:

git config --global difftool.idiff.cmd 'diff -i $LOCAL $REMOTE'

With this customization, I can see the case-insensitive comparison like so:

git difftool --tool idiff <other diff options> <Git references or files>

Eg.

git difftool -t idiff HEAD~1 -- my_schema.sql

Since git difftool prompts (for yes/no) every time before invoking the the tool, either use -y switch for difftool or add this config option to avoid the prompt:

git config --global difftool.prompt 0

UPDATE (2021/11/26): Here's a consolidated configuration I use, that allows me to use git idiff command that behaves almost identical to how git diff behaves.

git config --global difftool.idiff.cmd 'diff --unified=3 --color=always --ignore-case $LOCAL $REMOTE | less --raw-control-chars' git config --global difftool.prompt 0 git config --global alias.idiff 'difftool --tool idiff' 
like image 182
Gurjeet Singh Avatar answered Sep 29 '22 11:09

Gurjeet Singh