git diff --no-index --word-diff-regex=. --word-diff=porcelain ${site} ${site-prev} \
| grep '^[-+]' \
> ${site_diff}
if [[ $(wc -c < "${site_diff}") -gt 2000 ]]; then
echo "Warning: ${url} has changed a lot:"
# deal with it
fi
An overcrowded answer set already, but I wanted to share my solution from the automation perspective. To detect if a website is malfunctioning or has been hacked, I wanted an accurate, minimal diff between successive end-user snapshots. If there's huge changes, it may be reporting an error message, or may be blank, or have been maliciously changed, or accidentally drastically changed.
On the other hand, a CMS generates lots of trivial ID changes (such as cache timestamps) that do not indicate a real change, and the above is built to boil the issue down. If a few hundred IDs change in HTML tags, the net bytecount of difference will still be small, whereas if someone accidentally deletes several paragraphs, the byte count will be much larger. There's always a fuzzy middleground so I hand-wave at 2000 but probably even 500 is good.
It may also be a good idea to ignore whitespace changes depending on the application.
The essential options for me are:
--word-diff-regex=.
because words are arbitrarily long in code (SQL /
HTML / CSS / whatever), so this is actually a character based diff
--no-index
because these files are not in a repository, but YAY GIT!
--word-diff=porcelain
to easily extract the actual differences, which are easily detected by the -
/+
line prefixes, with
no surrounding context.
The output of the top line without the further grep/wc processing is still human friendly and quite clear, possibly useful for the OP.
git diff --word-diff --word-diff-regex=. f1 f2
works like a charm