Subject: Re: multiple source file extensions

From: Jeff King <[email-masked]>
Date: Fri, 1 May 2015 21:11:01 -0400

On Fri, May 01, 2015 at 08:49:14PM -0400, Josh Hagins wrote:

> If you're using a recent version of bash, you could enable the
> 'globstar' option:
> 
>     $ shopt -s globstar
>     $ git grep 'pattern' **/*.{cc,cpp,h}
> 
> Does that work?

That will only pick up files that are in the working tree. Which is fine
for a stock "git grep" with no options, but would not be right for
grepping in the index or an older tree. For that, you can ask git to
glob for you:

  git grep pattern -- '*.cc' '*.cpp' '*.h'

Note that the "--" is important (it's what tells git "these are
pathspecs and not revision names"; normally git will guess if you are
passing literal pathnames, but the glob patterns fool the guessing
machinery).

Unfortunately there is no way to use curly braces with git's pathspec,
so you have to write out three separate `*` arguments rather than using
the shell-style {cc,cpp,h}.

-Peff