There seems to be no Git diff options to support what you want to do. However, you can use the GIT_EXTERNAL_DIFF environment GIT_EXTERNAL_DIFF and a custom script (or any executable file created using your preferred script or programming language) to manipulate the patch.
I assume that you are on Linux; if not, you can customize this concept to suit your environment. Let's say you have a Git repo where HEAD has a file05 file that contains:
line 26662: $my_array[my_key]
And the file06 file, which contains:
line 19768: $my_array[my_key] line 19769: $my_array[my_key] line 19770: $my_array[my_key] line 19771: $my_array[my_key] line 19772: $my_array[my_key] line 19773: $my_array[my_key] line 19775: $my_array[my_key] line 19776: $my_array[my_key]
You change file05 to:
line 26662: $my_array["my_key"]
And you change file06 to:
line 19768: $my_array[my_key] line 19769: $my_array["my_key"] line 19770: $my_array[my_key] line 19771: $my_array[my_key] line 19772: $my_array[my_key] line 19773: $my_array[my_key] line 19775: $my_array[my_key2] line 19776: $my_array[my_key]
Using the following shell script, call her mydiff.sh and place it somewhere in our PATH :
#!/bin/bash echo " $@ " git diff-files --patch --word-diff=porcelain "${5}" | awk ' /^-./ {rec = FNR; prev = substr($0, 2);} FNR == rec + 1 && /^+./ { ln = substr($0, 2); gsub("\\[\"", "[", ln); gsub("\"\\]", "]", ln); if (prev == ln) { print " " ln; } else { print "-" prev; print "+" ln; } } FNR != rec && FNR != rec + 1 {print;} '
Command execution:
GIT_EXTERNAL_DIFF=mydiff.sh git --no-pager diff
It will display:
file05 /tmp/r2aBca_file05 d86525edcf5ec0157366ea6c41bc6e4965b3be1e 100644 file05 0000000000000000000000000000000000000000 100644 index d86525e..c2180dc 100644 --- a/file05 +++ b/file05 @@ -1 +1 @@ line 26662: $my_array[my_key] ~ file06 /tmp/2lgz7J_file06 d84a44f9a9aac6fb82e6ffb94db0eec5c575787d 100644 file06 0000000000000000000000000000000000000000 100644 index d84a44f..bc27446 100644 --- a/file06 +++ b/file06 @@ -1,8 +1,8 @@ line 19768: $my_array[my_key] ~ line 19769: $my_array[my_key] ~ line 19770: $my_array[my_key] ~ line 19771: $my_array[my_key] ~ line 19772: $my_array[my_key] ~ line 19773: $my_array[my_key] ~ line 19775: -$my_array[my_key] +$my_array[my_key2] ~ line 19776: $my_array[my_key] ~
This conclusion does not show changes for added quotes in file05 and file06 . The external diff script basically uses the Git diff-files to create the patch and filters the output through the GNU awk script to manipulate it. This sample script does not process all the different combinations of old and new files mentioned for GIT_EXTERNAL_DIFF , and does not output a valid patch, but you should have enough to get you started.
You can use Perl , Python difflib regular expressions or whatever is more convenient for you to implement an external comparison tool that suits your needs.