Skip to content

Instantly share code, notes, and snippets.

@dandavison
Created August 26, 2011 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dandavison/1172643 to your computer and use it in GitHub Desktop.
Save dandavison/1172643 to your computer and use it in GitHub Desktop.
git diff for regular diff usage
#!/bin/sh
# git diff for regular diff usage
cmd=$(basename "$0")
[ "$1" = "--help" ] && {
echo "$cmd [git diff options] fileA fileB"
exit 0
}
a="$1"
b="$2"
shift 2
# Last two args are the files to compare; the rest are options.
opts=""
while [ "$1" ] ; do
opts="$opts $a"
a=$b
b=$1
shift
done
tmpdir=$cmd-$(date '+%Y%m%d%H%M%S')
mkdir "$tmpdir" && ln "$a" "$tmpdir"/a || exit 1
(cd "$tmpdir" && git init && git add a) > /dev/null
ln -f "$b" "$tmpdir"/a
(cd "$tmpdir" && git diff --color=always $opts | sed -n '/@@/,$p' | less -FRSX)
rm -rf "$tmpdir" || {
echo "Failed to remove temp dir $tmpdir"
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment