Better git(1) diffs
Good old POSIX diff(1) can output diffs (patch files)
in serveral formats, "normal", ed(1), and the more useful
ones: copied context and the newer unified context.
git-diff(1) however can only output in unified context,
often it's quite good (although it is not fully-reverseble
if you ignore whitespace differences), however it can
become quite messy at times because it mixes the old
version and the new version in the same part of each hunk,
where as copied context first displays the old version
of the hunk and then the new version of the hunk (if
there is nothing removed however the old version is
skipped, and if there is nothing added, the new version
is skipped). In others words, copied context is similar
to side-by-side, except vertical. You can add the following
script to your PATH as git-cdiff, which
will let you type git cdiff instead of
git diff if you want to see your changes in
copied context format rather than unified context format.
#!/bin/sh
if test -z "${GIT_CDIFF_CONTEXT}"; then
git difftool -y -x "diff -c --color=always" "$@"
elif echo "${GIT_CDIFF_CONTEXT}" | grep -q '^-'; then
git difftool -y -x "diff ${GIT_CDIFF_CONTEXT} --color=always" "$@"
else
git difftool -y -x "diff -C${GIT_CDIFF_CONTEXT} --color=always" "$@"
fi | {
if test "$TERM" = linux; then
sed '/^\(\x1b\[[0-9;]*m\)* /s/\x1b\[[0-9;]*m//g'
else
sed '/^\(\x1b\[[0-9;]*m\)* /s/^/\x1b\[2m/g'
fi
} | {
if test -t 1; then
ifne less -R
else
cat
fi
}