title: How to check if the commit exists in a Git repository by its SHA-1
body: <p>In a similar topic <a href="https://stackoverflow.com/questions/4127967/validate-if-commit-exists">Validate if commit exists</a> they recommend:</p>
  
  <pre><code>git rev-list HEAD..$sha
  </code></pre>
  
  <p>If it exits without error code than the commit exists.</p>
  
  <p>But is it efficient enough just for validation?</p>
  
  <p>I was thinking about this option:</p>
  
  <pre><code>git cat-file commit $sha
  </code></pre>
  
  <p>Is it correct for my task and are there any other ideas?</p>