title: Git grep print only matching pattern
body: <p>In the manual for <code>grep</code>, we have <code>-o</code> to print <code>--only-matching</code> patterns.  Say <code>echo foobar | grep foo</code> would return <code>foobar</code>, but adding <code>-o</code> to <code>grep</code> would give only <code>foo</code>.</p>
  
  <p>Many <code>grep</code> options like <code>-P</code>, <code>-c</code>, etc, can be used in conjunction with <code>git</code> to search through all files in the Git index.  However, <code>git grep -o PAT</code> triggers an <code>error: unknown switch</code>o'`.</p>
  
  <p>How can I print only matched string for each file in the Git index? i.e. "<code>git grep -o PAT</code>"</p>
  
  <p>My trial:</p>
  
  <pre><code>for f in `git ls-files`; do grep -o PAT $f; done
  </code></pre>