GitHub:搜索旧版本的文件 [英] GitHub: searching through older versions of files
问题描述
我知道使用GitHub,我可以在回购中搜索所有当前版本的文件。不过,我还想搜索我的回购文件的旧版本。例如,我曾经在我的代码中有一个名为get_info()的函数,但在几个版本之前删除了它,是否可以搜索get_info并找到代码。如果无法使用GitHub,是否可以从git命令行中完成?
编辑
感谢@Mark Longair展示了如何通过git命令行完成这项工作。如果在GitHub中不可能,这将是一个很棒的功能。
目前,我不相信这是可能的在github网站上搜索存储库代码的完整历史记录 - 最接近的是使用 get_info 并将 -S
选项添加到 git log
中。例如:
git log -Sget_info -p
(在 -S
和搜索字词之间不应有空格)
(也注意:要搜索多个单词,环绕在'
中):
git log -S'get info'-p
最少应该在函数首次引入的位置以及删除该位置的位置找到该提交。我添加了 -p
,所以你也可以看到补丁 - 如果很多提交引入的变化提到了可能有用的功能。如果该函数只在另一个分支上,那么使用 - all
来搜索所有分支也是有用的。
Jefromi 在下面的评论中指出,git 1.7.4将引入 -G
选项作为替代方案 - 这一变化在Junio Hamano(git维护者)最近的一篇博客文章中进行了总结: http://gitster.livejournal.com/48191.html
I know that using GitHub I can search through all the current versions of my files in a repo. However, I would also like to search through the older versions of my repo files. For example, say, I used to have a function called get_info() in my code, but deleted it several versions ago, is it possible to search for get_info and find the code. If it is not possible using GitHub, is it possible from the git command line?
EDIT
Thanks to @Mark Longair for showing how this can be done from the git command line. If it's not possible in GitHub it would be a great feature to have.
Currently, I don't believe it's possible to search within the complete history of a repository's code on the github website - the closest is just searching within the current code of a repository with the "code search" option on this page.
However, from the command line, you can find any commits that introduced or removed lines mentioning get_info
with the -S
option to git log
. e.g.:
git log -Sget_info -p
(n.b. there should be no space between -S
and the search term)
(also note: to search for more than one word, surround in '
):
git log -S'get info' -p
So, at a minimum that should find the commit where the function was first introduced and the one that removed it. I added the -p
so you can also see the patches - if lots of commits introduced changes that mentioned the function that may be helpful. If the function was only on another branch it might also be useful to use --all
to search all branches.
Jefromi points out in a comment below that git 1.7.4 will introduce the -G
option as an alternative - this change is summarized in a recent blog post from Junio Hamano (git maintainer): http://gitster.livejournal.com/48191.html
这篇关于GitHub:搜索旧版本的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!