Skip to content

Instantly share code, notes, and snippets.

@AhiyaHiya
Created October 1, 2019 18:16
Show Gist options
  • Save AhiyaHiya/69f2735ca4e10b0cae273be2c0cc40e9 to your computer and use it in GitHub Desktop.
Save AhiyaHiya/69f2735ca4e10b0cae273be2c0cc40e9 to your computer and use it in GitHub Desktop.
Diff previous revision of file, against current version, with Git
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
#set -o xtrace
# The purpose of this script is to show the previous revision of a file, using git difftool
# Get the file in question.
readonly file_path=$1
# Set up our variable, our initial array and our final array.
sha=""
shas=$(git --no-pager log --pretty=format:"%H" -2 "$file_path")
array=()
# Parse the commit sha's.
while read -r sha; do
array+=("$sha")
done <<<"$shas"
# Now launch the difftool to see the file difference.
echo git difftool --no-prompt ${array[1]}...${array[0]} "${file_path}"
git difftool --no-prompt ${array[1]}...${array[0]} "${file_path}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment