2017-10-04 23 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

相关问题