Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The answer using <code>git cat-file</code> is using a git <strong>"plumbing"</strong> command, which is generally better for building scripts as the output format is not likely to change. The ones using <code>git show</code> and <code>git rev-parse</code> may need to change over time as they are using <a href="https://stackoverflow.com/questions/6976473/what-does-the-term-porcelain-mean-in-git"><strong>porcelain</strong></a> commands.</p> <p>The bash function I've been using for a long time uses <code>git rev-list</code>:</p> <pre><code>gitismerge () { local sha="$1" msha=$(git rev-list -1 --merges ${sha}~1..${sha}) [ -z "$msha" ] &amp;&amp; return 1 return 0 } </code></pre> <p>The list of porcelain/plumbing commands can be found in the docs for the top level <a href="https://git-scm.com/docs/git" rel="nofollow noreferrer"> git</a> command.</p> <p>This code uses <a href="https://git-scm.com/docs/git-rev-list" rel="nofollow noreferrer">git-rev-list</a> with a specific <a href="https://git-scm.com/docs/gitrevisions" rel="nofollow noreferrer">gitrevisions</a> query <code>${sha}~1..${sha}</code> in a way that prints a SHA's second parent if it exists, or nothing if it is not present, which is the exact definition of a merge commit.</p> <p>Specifically, <code>SHA~1..SHA</code> means <em>include commits that are reachable from SHA but exclude those that are reachable SHA~1, which is the first parent of SHA</em>.</p> <p>The results are stored in $msha and tested for emptiness using bash <code>[ -z "$msha" ]</code> failing (returning 1) if empty, or passing (returning 0) if non-empty.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload