2017-10-04 61 views
-1

我使用git 1.9.3或以上,我想排除的git grep的目錄列表 我嘗試這樣做: How to exclude certain directories/files from git grep search ,但它並沒有爲工作簡單的解決方案,以排除目錄列表中的git grep命令

例如: 我不想在'a'目錄和'b'目錄中搜索

什麼是簡單解決方案?

+1

wrt'It does not work' - see [what-do-you-mean-it-doesnt-work] (https://meta.stackexchange.com/questions/147616/what-do-you-mean-it-doesnt-work)。你[到目前爲止提出了12個問題](https://stackoverflow.com/users/8588509/alex),並沒有收到任何答案(對你而言)(我假設你沒有接受[接受](https://stackoverflow.com/help/someone-answers)任何)所以也許這個網站只是不適合你?否則請閱讀[詢問]如何在此提出問題。 –

回答

0

我不認爲有一種「官方」方式不是解決方法(就像您鏈接的.gitignore技巧)。

你可以試着管結果成倒grep的搜索像這樣:

git grep menu | grep -v public

哪裏public是你要過濾掉的目錄。

雖然你不會得到彩色輸出。

1

對於上面的例子,怎麼樣:

git grep -e menu --and --not -e public 

從該名男子頁:

 --and, --or, --not, (...) 
     Specify how multiple patterns are combined using Boolean expressions. --or is the default operator. 
     --and has higher precedence than --or. -e has to be used for all patterns. 

@Alex - 根據您的意見,我敢肯定上面可以使用,但你應該也可以使用'pathspec' - https://git-scm.com/docs/gitglossary.html#def_pathspec。我不明白爲什麼「這不起作用」。如果'a'和'b'是你想要從結果中排除的dirs:

git grep -e pattern -- . ":(exclude)a" ":(exclude)b" 
+0

我認爲你會混淆。我討論排除搜索目錄。不是搜索的字符串@pynewbie – Alex

+0

好的,您可以努力提供您正在嘗試搜索的具體示例嗎?除此之外,你不能指望任何人不會困惑:) – pynewbie

+0

例如: 我不想搜索'a'目錄和'b'目錄@pynewbie – Alex