Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to ignore certain directories by default when using git grep? [duplicate]

Tags:

git

grep

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?

like image 989
Kit Sunde Avatar asked Dec 07 '25 01:12

Kit Sunde


2 Answers

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.

like image 130
kynan Avatar answered Dec 08 '25 13:12

kynan


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.

like image 22
asmeurer Avatar answered Dec 08 '25 14:12

asmeurer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!