Skip to content

Instantly share code, notes, and snippets.

@podanypepa
Last active April 11, 2020 14:34
Show Gist options
  • Save podanypepa/bc92763e11c404de9f271fa8f9d55217 to your computer and use it in GitHub Desktop.
Save podanypepa/bc92763e11c404de9f271fa8f9d55217 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ -z `git rev-parse --is-inside-work-tree 2>/dev/null` ]; then
echo "${PWD} isn't git repo dir"
exit 1
fi
if [ $# -lt 1 ]; then
echo "bad ussage: 1.arg is name of file"
echo "nonmandatory 2.arg = num of last commits to see"
exit 1
fi
if [ ! -f "$1" ]; then
echo "file $1 doesn't exist"
exit 1
fi
N=2 # default see changes between last 2 commits
[ $# -eq 2 ] && ((N=$2+1))
START=""
END=""
for i in $(git log -n $N --pretty=oneline $1 | awk '{print $1}')
do
[ -z $START ] && START=$i || END=$i
done
if [ -z "$START" -o -z "$END" ]; then
echo "no changes on $1"
exit 0
fi
git diff $START..$END $1 | vim -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment