如何git grep只有一组文件扩展名 [英] How to git grep only a set of file extensions

查看:196
本文介绍了如何git grep只有一组文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何执行git grep并将选中的文件限制为一组文件。我希望能够查找.cpp和.h文件寻找MyFunc的内容。例如:

  git grepMyFunc -  *。[hc] * 

然而,这也匹配.c文件和.cs文件。

解决方案

  git grepMyFunc - *。{cpp,h} 

甚至更简单:

  git grepMyFunc -  * .cpp * .h 

git词汇表中对pathspec的解释提到使用 fnmatch(3)匹配模式 。与外壳和公用程序卷所描述的模式(包括多个字符)匹配IEEE Std 1003.1-2001,第2.13.1节,并且将导致匹配多个字符的基本正则表达式,并给了我第一个解决方案。

进一步的研究使我找到了第二个解决方案,通过查看 glob


How do you perform a git grep and limit the files checked to a set of files. I would like to be able to grep the contents of .cpp and .h files looking for MyFunc. eg:

git grep "MyFunc" -- *.[hc]*

However this also matches, .c files and .cs files.

解决方案

This can be achieved when using git bash in Windows by using:

git grep "MyFunc" -- *.{cpp,h}

or even simpler:

git grep "MyFunc" -- *.cpp *.h

The explanation of pathspec on the git glossary mentions that patterns are matched using fnmatch(3). Which matches patterns (including multiple characters) as described by Shell and Utilities volume of IEEE Std 1003.1-2001, Section 2.13.1 and leads to basic regular expressions matching multiple characters and gave me the first solution.

Further research lead me to the second solution by looking into documentation on glob.

这篇关于如何git grep只有一组文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆