2016-06-08 37 views
1

我尝试使用git grep -i 'search' README.md,输出中发现了一些我有兴趣查看的行,但这些行没有打印出git sha,以便我可以获得关于这些提交的更多信息。输出如下所示:当我使用git grep时,我如何看到commit sha?

README.md:ElastiCache, ElasticSearch, and RDS setup with Terraform 

如何查看此行的git sha?我查看了文档,甚至没有包含“commit”或“sha”这个词。

+1

我相信你目前使用'git grep'只会搜索工作目录和blob。如果你想搜索实际的提交历史,你将需要一个[更复杂的命令](http://stackoverflow.com/questions/2928584/how-to-grep-search-committed-code-in-the-git-history )。 –

+0

我不认为你明白'git grep'的作用。这实际上只是一个排除'.git'目录的'grep -r'。也许你正在寻找'git log --grep'或'git log -S''。 – Mort

回答

1

没有附加规范,git grep只是看当前提交。

要查看其他提交(或索引),您必须为它们命名(或使用--cached)。例如,比较:

$ git grep asdf 
Documentation/rev-list-options.txt: ``asdf'', and a file `quux` exists with con 
t/t5516-fetch-push.sh: test_must_fail git push >.git/bar --porcelain asdfasdfas 
t/t9100-git-svn-basic.sh:  echo asdf > dir && 
t/t9132-git-svn-broken-symlink.sh:asdf 
t/t9132-git-svn-broken-symlink.sh:test_expect_success SYMLINKS '"bar" is a symli 
t/t9132-git-svn-broken-symlink.sh:  (cd x && test xasdf = x"$(git cat-file b 

VS:

$ git grep asdf HEAD^ HEAD~3 
HEAD^:Documentation/rev-list-options.txt: ``asdf'', and a file `quux` exists wi 
HEAD^:t/t5516-fetch-push.sh: test_must_fail git push >.git/bar --porcelain as 
HEAD^:t/t9100-git-svn-basic.sh: echo asdf > dir && 
HEAD^:t/t9132-git-svn-broken-symlink.sh:asdf 
HEAD^:t/t9132-git-svn-broken-symlink.sh:test_expect_success SYMLINKS '"bar" is a 
HEAD^:t/t9132-git-svn-broken-symlink.sh:  (cd x && test xasdf = x"$(git ca 
HEAD~3:Documentation/rev-list-options.txt: ``asdf'', and a file `quux` exists w 
HEAD~3:t/t5516-fetch-push.sh: test_must_fail git push >.git/bar --porcelain as 
HEAD~3:t/t9100-git-svn-basic.sh:  echo asdf > dir && 
HEAD~3:t/t9132-git-svn-broken-symlink.sh:asdf 
HEAD~3:t/t9132-git-svn-broken-symlink.sh:test_expect_success SYMLINKS '"bar" is 
HEAD~3:t/t9132-git-svn-broken-symlink.sh:  (cd x && test xasdf = x"$(git ca 

如果您列出多个树(或提交的ID)来搜索,结果你的符前缀,让你知道他们去与一个。

+0

有没有办法做到这一点的提交范围,即'git grep asdf HEAD^.. HEAD〜3'? –

+0

@JeffPuckettII与'git grep'不太一样;因为你通常需要''g''或'-G'''git log'。虽然我会注意到,你可以使用'git rev-list'来创建任意大的commit-ID列表,并使用'$(...)'或者xargs将它们传递给'git grep' ... – torek

1

git blame README.md | grep -i 'search'

+0

不错!请注意,这仍然只会显示当前在工作目录中的更改的最新历史记录。 –

+0

是的,因为这是最近的历史,这对我不起作用。 –

相关问题