Without additional specifications, git grep
just looks at the current commit.
To look in other commit(s) (or the index), you must name them (or use --cached
). For instance, compare:
$ 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
If you list multiple trees (or commit IDs) to search, the results have your specifiers prefixed, so that you know which one they go with.