测试文档1.txt的文件内容如下:
一、在指定commit节点中的所有文件,列出包含指定字符串的每一行。
git grep '指定字符串' [commit节点]
# 如果没有指定commit节点,表示要搜索文件夹中所有的文件。
# 例:
git grep '1' head
结果:
如果要查找的字符不止一个,可以使用:
git grep -e '指定字符串1' -e’指定字符串2' -e '指定指定串3' [commit节点]
# 例:
git grep -e 'aaa -e ’bbb' -e 'ccc' head
同时也可以与or,and等逻辑运算符一起使用
查找有’aaa’及‘bbb’字符的文件:
git grep -e 'aaa --and -e ’bbb' head^
查找有’aaa’或‘bbb’字符的文件:
git grep -e 'aaa --or -e ’bbb' head^
查找含有字符串’aaa’,而且含有‘bbb’或‘ccc’的文件:
# 其中\为转义符
git grep -e 'aaa'--and \( -e 'bbb' -e 'ccc' \) head^