The accepted answer works well for manual inspection of the result, but has a fatal flaw for scripting: the commit message itself could contain a line starting with "parent", and you might accidentally catch that, instead of the meta data at the top of the output.
A more reliable alternative is:
git show --summary <commit>
And check if a line starts with Merge:
. This is similar to git cat-file, but it will prefix the commit message with spaces, so you can grep for it safely in a script:
git show --summary HEAD | grep -q ^Merge:
This will return 0 for merge commits, 1 for non-merge commits. Replace HEAD by your desired commit to test.
Example usage:
if git show --summary some-branch | grep -q ^Merge: ; then
echo "some-branch is a merge"
fi
This works because the commit message itself is prefixed by 4 spaces, so even if it contained a line starting with "Merge:", it would look like Merge:..
, and the regex would not catch it. Note the ^
at the start of the regex, which matches the start of the line.