夜间模式
23. 检索
git grep [options] pattern [-- [pathspec...]]
pattern
字符串或者正则表达式
[不同的模式]
pathspec
搜索的文件或者目录
常用选项
-i
:忽略大小写。shgit grep -i "pattern"
1-n
:显示匹配行的行号。shgit grep -n "pattern"
1-v
:反向匹配,显示不包含匹配模式的行。shgit grep -v "pattern"
1-c
:只显示匹配的行数。shgit grep -c "pattern"
1-l
:只显示包含匹配模式的文件名。shgit grep -l "pattern"
1--cached
:在索引(暂存区)中搜索。shgit grep --cached "pattern"
1<commit>
:在指定提交中搜索。shgit grep "pattern" HEAD git grep "pattern" commit_hash
1
2<branch>
:在指定分支中搜索。shgit grep "pattern" branch_name
1--
:分隔符,用于区分路径和模式。shgit grep "pattern" -- path/to/file_or_directory
1
例子:
sh
$ git grep 测试
revert.txt:测试1
revert.txt:测试2
revert.txt:测试3
Yee@Yee MINGW64 ~/Desktop/gitdome (dev)
$ git grep -n 测试
revert.txt:1:测试1
revert.txt:3:测试2
revert.txt:5:测试3
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10