title: Pass commit hash to a git function in a pretty format
body: <p>My git repo is huge (and created by people knowing only clearcase) and I want to find all the commits refering to an issue Id on all branches and at the same time knowing which branches <strong>contain</strong> the commits.</p>
  
  <p>However, the following attempt won't work as the <code>$(git branch …)</code> is expanded before the <code>%h</code> is.</p>
  
  <pre><code>git log --all --oneline --grep="FOO-1337" --pretty=format:"%C(auto)%h $(git branch --contains=%h)"
  </code></pre>
  
  <p>Is there a shorter solution than looping through the output of <code>git log</code> as in the following:</p>
  
  <pre class="lang-sh prettyprint-override"><code>for commit in $(git log --all --oneline --grep="FOO-1337" --pretty=format:"%h");
  do
       branches=$(git branch --contains=$commit | tr '\n' ',')
       git show --oneline --quiet --pretty=format:"%C(auto)%h ${branches}" $commit; 
  done
  </code></pre>
  
  <p>(which I can, of course define as an alias but it seems a bit contrived to me)</p>