Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.