Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
diff a branch to a base branch
#!/usr/bin/env bash
help() {
cat <<EOS
$0 [-h | --help] [base] [head]
Diff current branch (or [head], if passed) to [base]
EOS
}
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--help)
help
exit 1
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
. "$(git --exec-path)/git-sh-setup"
base_branch="$1"
head_branch="${2:-HEAD}"
echo "$base_branch"
echo "$head_branch"
exec git diff $(git merge-base "$base_branch" "$head_branch").."$head_branch"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment