2012-12-13 24 views
58

我知道,如果我想要到grep的模式僅在帶有特定擴展名的文件,我可以這樣做:通過文件擴展名的git grep的

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

我一直在試圖尋找一種方法來也可以通過git grep來做到這一點(利用git grep的速度利用其存儲的樹索引的速度),但無濟於事。我看到here排除某些文件類型是不可能的。

回答

99

是的,比如說:

git grep res -- '*.js' 
+2

一個輕微的修改 - 如果您庫中的根不是,'混帳grep的資源 - 「/ * .js''可能會更好...... – twalberg

+1

@twalberg:但是評論表明他想從當前目錄[向下]看,當然? –

+0

啊......對......這個問題沒有具體說明,但代碼塊中的評論確實如此。 – twalberg

2

嘗試這樣做:

find . -type f -iname '*.js' -exec grep -i 'pattern' {} +