How to perform case insensitive diff in Git
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'
To expand on Gurjeet Singh's answer, and caw's colordiff
comment, in Windows I did the following to get it all tied together:
If needed, install Strawberry Perl distribution for Windows. Any Windows Perl distribution should work, but Strawberry Perl is free software/open source and comes with batteries included. Heed caution with the Web site result because there's a NSFW site with a similar domain IIRC. Use Google instead of guessing.
Install MinGW/MSYS. Git for Windows already comes with a build of MSYS so you might be able to just use its
make
, but your mileage may vary.Download and install the
colordiff
Perl script. I edited the Makefile to change the install location to~/bin
and~/etc
(where~
is%USERPROFILE%
) because~/bin
is already in myPATH
. Adjust as needed.(cmd.exe) Edit your registry environment variables (search start menu for environment variables) and add
.PL
toPATHEXT
(and whateverbin/
you used forPATH
if necessary).(cmd.exe) Create a bash script (e.g.,
~/bin/colordiffless.bash
) that passes any arguments on tocolordiff.pl
(colordiff
accepts diff options and passes them on automatically) and pipes throughless
. The color codes output bycolordiff
are ANSI, which cmd.exe will not understand, butless
does. You also restore Git's pager behavior this way (configureLESS
environment variable if necessary).#!/bin/bash colordiff.pl "$@" | less
Setup the alias as Gurjeet did, except instead of invoking
diff
directly, invoke your bash script. The color codes output are ANSI so you'll need something to convert them. I happen to know that MSYSless
will do just that, and you also preserve the pager behavior of Git!git config --global difftool.cldiff.cmd "colordiffless.bash -ui $LOCAL $REMOTE"
(from cmd.exe, so the double-quotes are literal and the
$LOCAL
and$REMOTE
are literal text too)Finally, alias the
difftool
command so you can type a single, custom command instead of thedifftool
command:git config --global alias.cldiff "difftool -y -t cldiff"
Edit
I was mistaken about the pager behavior coming back. difftool
invokes the command for each file so instead of getting a single pager output with every diff, you will get a pager for each file. To solve that, you will likely want to wrap difftool -y
in a script and pipe its entire output to less
instead.