3

With south in Django we have something like:

/app
  /migrations
    .. migration files.

Since migration files represent historical structure rather than what's currently in there I would prefer to not search through them each time. Is there some way I can exclude them by default when running git grep?

Stals
  • 1,543
  • 4
  • 27
  • 52
Kit Sunde
  • 35,972
  • 25
  • 125
  • 179

3 Answers3

2

This is a bad hack, but it might work for you: create app/migrations/.gitattributes with the following content

* binary

to mark all migrations as binary files and then use git grep -I to skip binary files.

If you also want to ignore migrations in diffs you can do so by changing the content of .gitattributes to

* binary -diff

There is discussion about adding attributes respected by grep, so there might be a proper solution one day.

kynan
  • 13,235
  • 6
  • 79
  • 81
1

I have an alias git gr for git grep that enables colors and case insensitivity. You could do this and add excludes. And it's faster to type!

Otherwise, there's no way to change the default behavior of Git commands for the most part, because they are used directly internally.

asmeurer
  • 86,894
  • 26
  • 169
  • 240
  • Not sure what you mean by "add excludes", `git grep` doesn't support exclude patterns. Or do you alias `git gr` to a regular `grep` via a `!` alias? – kynan Jan 09 '13 at 00:51
  • Hmm. I never noticed that. If you don't care about the blob specific features of `git grep`, I guess you could just use normal grep, and make sure to exclude `.git`. – asmeurer Jan 09 '13 at 03:11
  • You could create an alias with a default list of files to *include* not containing your migrations folder as discussed [in this answer](http://stackoverflow.com/a/14226610/396967) – kynan Jan 09 '13 at 14:04
0

I don't think there is a solution using the git grep command alone.

A workaround I can think of is to add the files/folders you want to ignore to the .gitignore file ans then execute the command like :

git grep --exclude-standard
Yannick Blondeau
  • 9,465
  • 8
  • 52
  • 74
  • I can't do that, I need the database migrations in my repo sadly. – Kit Sunde Oct 07 '12 at 19:31
  • For anyone who's been wondering: while you can add tracked files to `.gitignore`, `--exclude-standard` applies only to untracked files. – kynan Jan 09 '13 at 13:54