sdbbs
sdbbs

Reputation: 5384

How to grep through all files in a given revision in git?

Let's say I have a git, with a revision/commit with hash aaaaaaa in the past, which described a state with three files, a.txt, b.txt, and c.txt.

So, let's say there were more changes and commits, and current HEAD is at commit bbbbbbb, which has files a.txt, e.txt and f.txt - in other works, b.txt and c.txt from earlier have been deleted somewhere along the way.

Now, what I want to do, is search for a phrase in the files as they were in commit aaaaaa, and find in which file(s) it occurs.

Typically, I could do:

$ git checkout aaaaaaa
$ grep -r 'phrase' .

... but, let's say I do not want to checkout, and I want to keep my current state at HEAD, that is commit bbbbbbb.

Is there a git command, that will allow me to grep through all the files as in commit aaaaaaa, while the checked out files are currently at HEAD of bbbbbbb - without having to checkout aaaaaaa?

Upvotes: 1

Views: 203

Answers (1)

wjandrea
wjandrea

Reputation: 32963

git grep takes an optional tree argument. So it's this simple:

git grep 'phrase' aaaaaaa

-r and . are implied with git grep.

Upvotes: 3

Related Questions