Ignore any blank space or line break in git-diff

Executing command git diff --help gives some options like

--ignore-cr-at-eol
    Ignore carriage-return at the end of line when doing a comparison.

--ignore-space-at-eol
    Ignore changes in whitespace at EOL.

-b, --ignore-space-change
    Ignore changes in amount of whitespace. This ignores whitespace at line end, and considers all other sequences of one or more whitespace
    characters to be equivalent.

-w, --ignore-all-space
    Ignore whitespace when comparing lines. This ignores differences even if one line has whitespace where the other line has none.

--ignore-blank-lines
    Ignore changes whose lines are all blank.

Which you can combine according to your need, Below command worked for me

git diff --ignore-blank-lines --ignore-all-space --ignore-cr-at-eol

This does the trick for me:

git diff --ignore-blank-lines

git diff supports comparing files line by line or word by word, and also supports defining what makes a word. Here you can define every non-space character as a word to do the comparison. In this way, it will ignore all spaces including white-spcae, tab, line-break and carrige-return as what you need.

To achieve it, there's a perfect option --word-diff-regex, and just set it --word-diff-regex=[^[:space:]]. Refer to doc for detail.

git diff --no-index --word-diff-regex=[^[:space:]] <file1> <file2>

Here's an example. I created two files, with a.html as follows:

<html><head><title>TITLE</title><meta>

With b.html as follows:

<html>
    <head>
        <title>TI==TLE</title>
        <meta>

By running

git diff --no-index --word-diff-regex=[^[:space:]] a.html b.html

It highlights the difference of TITLE and TI{+==+}TLE in the two files in plain mode as follows. You can also specify --word-diff=<mode> to display results in different modes. The mode can be color, plain, porcelain and none, and with plain as default.

diff --git a/d.html b/a.html
index df38a78..306ed3e 100644
--- a/d.html
+++ b/a.html
@@ -1 +1,4 @@
<html>
    <head>
            <title>TI{+==+}TLE</title>
                    <meta>