How is git grep in the whole tree when I enter a subdirectory?

Usually, when I issue git grep, it will only search the current directory and below, for example

$ cat A
1
$ cd d
$ cat B
1
$ git grep 1
B:1
$ cd ..;git grep 1
A:1
B:1

How can I say git grep"search the entire tree, regardless of the current working directory in which I am located?

+5
source share
3 answers

Git aliases that run shell commands are always executed in the top-level directory (see the git configman page ), so you can add this to your .gitconfigfile:

[alias]
    rgrep = !git grep

Alternatively, you can use git rev-parse --show-toplevelto get the root directory, which you can then pass git grepin as the basis for a script or alias:

git grep $pattern -- `git rev-parse --show-toplevel`
+8

:/

git grep pattern -- :/

Git 1.9.1 , : fooobar.com/questions/16315/...

+4

Add this to your Git config file to create an alias grepallthat will do what you want:

[alias]
    grepall = !git grep

(Non-native aliases, such as those starting with !, always start from the top level of the repository.)

0
source

All Articles