Skip to content

Instantly share code, notes, and snippets.

@laanwj
Created September 3, 2015 23:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laanwj/ef8a6dcbb02313442462 to your computer and use it in GitHub Desktop.
Save laanwj/ef8a6dcbb02313442462 to your computer and use it in GitHub Desktop.
Find/show merge commits
#!/bin/bash
usage() {
echo "git-merge-point <commitid>"
exit 1
}
[ -n "$1" ] || usage
# Make sure we are in a git directory
git rev-parse --is-inside-work-tree >&- || exit $?
# Get commit name and upstream name
commit="$1"
upstream="${2:-HEAD}"
# Get list merges leading from $commit to $upstream
IFS=$'\n' read -d '' -r -a ancestry < \
<(git rev-list --ancestry-path --merges "$commit..$upstream" --)
# Get list of merges directly into $upstream
IFS=$'\n' read -d '' -r -a merges < \
<(git rev-list --first-parent --merges "$commit..$upstream" -- | tac)
# Find merge point
for merge in "${merges[@]}"; do
for sha in "${ancestry[@]}"; do
if [ "$sha" = "$merge" ]; then
echo $sha
exit 0
fi
done
done
echo 'not merged' >&2
exit 1
#!/bin/bash
usage() {
echo "git-show-merge <commitid>"
exit 1
}
[ -n "$1" ] || usage
COMMIT=$(git-merge-point $1)
[ -n "$COMMIT" ] || {
echo "Not found or never merged"
exit 1
}
git show --show-signature $COMMIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment