The git-diff-extended script replaces the standard diff command with git diff to be able to compare strings on the commandine (and not only files). Additionally we make use of the great diff-highlight script (https://github.com/git/git/tree/master/contrib/diff-highlight) which improves git diff highlighting to show per character differences.
- install git
-
cp git-diff-extended.sh in a certain directory, e.g. ~/bin
-
add this directory (~/bin) to $PATH, if not yet the case. Just add the following in ~/.bash_profile
export PATH=~/bin:$PATH
-
add the following alias to ~/.bash_profile
alias diff=git-diff-extended.sh $1
-
search the diff-highlight script in your git installation. The diff-highlight tool is part of git distributions but unfortunately its a bit hidden in the file system,
e.g. on MacOS it could be located in /opt/homebrew/Cellar/git/<git-version>/share/git-core/contrib/diff-highlight/ or /usr/local/Cellar/git/<git-version>/share/git-core/contrib/diff-highlight/diff-highlight
-
cp diff-highlight to ~/bin (with the small risk that you miss updates on the diff-highlight with newer git versions)
alternatively you can create a link, but this means it will not work after git update (because git version is in the path)
-
Add the following to ~/.gitconfig
[pager]
diff = diff-highlight | less
log = diff-highlight | less
show = diff-highlight | less