Chi-Lan Chi-Lan - 1 year ago 95
Git Question

git grep in the whole tree

Normally when I issue

git grep
, it will only search the current directory and below, for instance

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

How can I tell
git grep
"search the entire tree, no matter the current working directory I'm in"?

Answer Source

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

    rgrep = !git grep

Alternatively, you could use git rev-parse --show-toplevel to get the root directory, which you could then pass to git grep as the basis of a script or alias:

git grep $pattern -- `git rev-parse --show-toplevel`
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download