当我使用git grep时,如何查看提交sha?

时间:2016-06-08 00:46:07

标签: git git-grep

我尝试使用git grep -i 'search' README.md并且输出找到了一些我感兴趣的行,但是这些行没有打印出git sha,因此我可以获得有关这些提交的更多信息。输出看起来像这样:

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

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

2 个答案:

答案 0 :(得分: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)进行搜索,结果会以您的说明符为前缀,以便您知道它们与哪一个一起使用。

答案 1 :(得分:1)

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