Skip to content

Instantly share code, notes, and snippets.

@Osse
Created August 18, 2016 13:54
Show Gist options
  • Save Osse/f104ea3b8bb015b72b24aca1db6928fa to your computer and use it in GitHub Desktop.
Save Osse/f104ea3b8bb015b72b24aca1db6928fa to your computer and use it in GitHub Desktop.
#!/bin/bash
# Assuming master is the main branch and first argument is topic branch
topicsha=$(git rev-parse "$1")
mergebase=$(git merge-base master "$1")
if [[ $topicsha != $mergebase ]]; then
# Not merged yet! ez
git diff master..."$1"
else
# Oh no, it's already merged. Find merge in log
# This prints sha parent1sha [ parent2sha ... ]
mergecommit=$(git log --format='%H %P' |
awk -vtopicsha="$topicsha" ' $3 == topicsha { print $1; exit }'
)
if [[ -n $mergecommit ]]; then
# ez
git diff "$mergecommit^1...$mergecommit^2"
else
echo oops >&2;
exit 1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment