Skip to content

Instantly share code, notes, and snippets.

@alice1017
Created August 10, 2018 01:34
Show Gist options
  • Save alice1017/abccac74ab40ec52f47db5485ea75977 to your computer and use it in GitHub Desktop.
Save alice1017/abccac74ab40ec52f47db5485ea75977 to your computer and use it in GitHub Desktop.
Display the difference of two git hash
#!/bin/bash
# coding: utf-8
# git-hashdiff
# Display the difference of two git hash.
# Args: $1 -- git reference (HEAD, origin/master etc.)
# $2 -- another reference
check_ref() {
local ref=$1
git rev-parse "$ref" > /dev/null 2>&1
if [ ! "$?" = "0" ];then
echo "fatal: the invalid reference:"$ref"" 1>&2
exit 1
fi
}
if [ ! "$#" = "2" ];then
echo "usage: git hashdiff [ref_a] [ref_b]" 1>&2
exit 1
fi
declare ref_one=$1 # git reference (HEAD, origin/master etc.)
declare ref_two=$2 # git reference
check_ref "$ref_one"
check_ref "$ref_two"
declare hash_one="$(git rev-parse $ref_one)"
declare hash_two="$(git rev-parse $ref_two)"
printf "a: %s\n" $hash_one
printf "b: %s\n" $hash_two
if [ "$hash_one" = "$hash_two" ];then
exit 0
else
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment