git grep por extensiones de archivo


Sé que, si quisiera grep para un patrón solo en archivos con ciertas extensiones, podría hacer esto:

// searches recursively and matches case insensitively in only javascript files
// for "res" from the current directory
grep -iIr --include=*.js res ./

He estado tratando de buscar una manera de hacer esto también a través de git grep (para aprovechar la velocidad de git grep de los índices que almacena con su árbol), pero fue en vano. Vi aquí que excluir ciertos tipos de archivos no es posible.

Author: Vinay, 2012-12-14

2 answers

Sí, por ejemplo:

git grep res -- '*.js'
 109
Author: CB Bailey,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-12-13 21:16:09

Intenta hacer esto:

find . -type f -iname '*.js' -exec grep -i 'pattern' {} +
 3
Author: Gilles Quenot,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-12-13 20:14:35