Created
August 26, 2011 03:47
-
-
Save dandavison/1172643 to your computer and use it in GitHub Desktop.
git diff for regular diff usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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