Skip to content

Instantly share code, notes, and snippets.

@matthiasbeyer
Created April 17, 2021 09:33
Show Gist options
  • Save matthiasbeyer/171ecfb8c6d75cd43c6beb426a254460 to your computer and use it in GitHub Desktop.
Save matthiasbeyer/171ecfb8c6d75cd43c6beb426a254460 to your computer and use it in GitHub Desktop.
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