在git仓库中找到一个函数 [英] Locating a function in a git repository
问题描述
我是Github和Jupyter笔记本的新手.
我想在git存储库中找到特定的函数,该怎么做?
我知道我可以使用Git grep,但是我不知道该命令.
另外,我可以使用Jupyter笔记本电脑执行此操作吗?还是必须使用终端机?
I am new to Github and Jupyter notebook.
I want to find a specific function in a git repository, how do I do it?
I have come to know that I could use Git grep, but I don't know the command.
Also, can I use Jupyter notebook to do this or do I have to use the terminal?
推荐答案
我不了解 Jupyter Notebook ,但请使用终端.确保您已经git clone
d存储库并且在终端中其目录内.然后在终端上执行git grep
.
I don't know about Jupyter Notebook, but use the terminal. Make sure you have already git clone
d the repository and are inside its directory in the terminal. Then do git grep
from the terminal.
1.使用git grep
(您必须 必须位于git存储库中):
1. With git grep
(you must be inside a git repo):
区分大小写的搜索. -n
显示了在其中也找到结果的行号.
Case-sensitive search. The -n
shows the line number where the result is found too.
git grep -n "my regular expression search string"
不区分大小写的搜索(在此处添加-i
):
Case insensitive search (add -i
here):
git grep -ni "my case insensitive regular expression search string"
查找功能用法(下面的左括号是可选的)
Find a function usage (left parenthesis below is optional)
git grep -n "myFunc("
Grep进行正则表达式搜索.谷歌它的详细信息.正则表达式是进行非常特定的字符串匹配的一种非常有效的方法.当您学习基础知识时,请在此处使用此工具练习测试和检查正则表达式(regex)搜索: https://regex101.com /.
Grep does regular expression search. Google it for details. Regular expressions are a very powerful way to do very specific string matching. As you learn the basics, practice testing and checking your regular expression (regex) searches with this tool here: https://regex101.com/.
2.使用常规grep
(可在任何地方使用,但运行速度比git grep
慢100倍):
与上面相同,除了为'r'ecursive添加-r
(用于搜索目录).如果您也想遵循符号链接,请使用-R
而不是-r
.
Same as above, except add -r
for 'r'ecursive (to search into directories). If you want to follow symbolic links too, use -R
instead of -r
.
示例:
区分大小写的搜索. -n
显示了在其中也找到结果的行号.
Case-sensitive search. The -n
shows the line number where the result is found too.
grep -rn "my regular expression search string"
不区分大小写的搜索(在此处添加-i
):
Case insensitive search (add -i
here):
grep -rni "my case insensitive regular expression search string"
查找功能用法(下面的左括号是可选的)
Find a function usage (left parenthesis below is optional)
grep -rn "myFunc("
查找功能(以下符号链接:添加-R
):
Find a function (following symbolic links: add -R
):
grep -Rn "myFunc("
奖金:按名称查找文件:
只需使用管道运算符(|
)将find
的输出管道传输为grep
的输入:
Bonus: find a file by name:
Just pipe the output of find
to be the input to grep
with the pipe operator (|
):
find | grep -ni "my_file_name"
或者,将-L
与find
一起使用以跟随符号链接:
Or, use -L
with find
to follow symbolic links:
find -L | grep -ni "my_file_name"
请注意,上面的-i
用于不区分大小写的文件名搜索.删除它以匹配大小写.
Notice the -i
above is for case-insensitive filename searches. Remove it to match the case too.
- 多年来的随机体验,谷歌搜索和与人交谈
- 阅读手册页(手册):
- Random experience, Googling, and talking to people over the years
- Read the man (manual) pages:
-
man git grep
-
man grep
-
man find
man git grep
man grep
man find
相关:
这篇关于在git仓库中找到一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!