2012-12-14 42 views

回答

11

使用git grep定位提交:

git grep "string" $(git rev-list --all) 

git rev-list --all使得搜索项目的整个历史。

这将会给像这样的输出:

<commit>:<path>:<matched line> 

然后你可以使用git branch --contains找出提交哪个分支是:

git branch --contains <commit> 
+0

我可以指定仅搜索一个文件/路径吗? (例如,我正在寻找一个特定的灯具,只想搜索这个路径) –

+1

是:'git grep“字符串”$(git rev-list --all) - path'。 – jszakmeister

+7

这对大历史无效:( 'git grep'abc'echo $(git rev-list --all)' 'zsh:参数列表太长:git' – tback

1

git branch "branch-name"更改分支,然后在存储库根目录中执行git grep "specific string"。如果你没有太多的分支,这应该让你快速到达。

1

如果上述git grep "string"变化给你“列表太长“的错误,你可以用git log -S代替。 -S选项搜索已提交的文件的内容:(更多在“临Git的”书下"searching"

git log -Sstring # look for string in every file of every commit 
git log -Sstring -- path/to/file # only look at the history of the named file 

相关问题