Peter Willemsen
Peter Willemsen

Reputation: 735

Git grep: Sometimes empty result even when the word exists in a file

I was looking for this before but I couldn't find it. Using: Ubuntu 11.10 64-bit

I want to find a source file a made a time ago, but couldn't find it. So I used git grep to find it:

git rev-list --all | (
    while read revision; do
        git grep -F 'leaderboard' $revision
    done
)

But the result is an empty response! Which is really weird, because 'leaderboard' actually IS in the repository, it's in the current revision, but also in older ones (in an XML file):

<query name="leaderboard.getById">

Other searches gives results, like messages or something will work.

Upvotes: 1

Views: 742

Answers (2)

VonC
VonC

Reputation: 1327784

Note: the answer can still be empty even with the right shell syntax... when the index is corrupted.

Git 2.18 (Q2 2018, 6 years later) now avoids the empty answer.

The error behaviour of "git grep" when it cannot read the index was inconsistent with other commands that uses the index, which has been corrected to error out early.

See commit b2aa84c (15 May 2018) by Stefan Beller (stefanbeller).
(Merged by Junio C Hamano -- gitster -- in commit 6ac5aca, 30 May 2018)

grep: handle corrupt index files early

Any other caller of 'repo_read_index' dies upon a negative return of it, so grep should, too.

Upvotes: 0

Todd A. Jacobs
Todd A. Jacobs

Reputation: 84423

Your syntax leads to an ambiguous redirect in the shell. This should work for you:

git grep -F 'leaderboard' $(git rev-list --all)

Upvotes: 1

Related Questions