I'm a big fan of git grep. Does an equivalent exist in Subversion?


As answered in Exclude .svn directories from grep:

grep --exclude-dir=".svn"

This svngrep function provides basic funtionality similar to git grep:

svngrep() { grep  --color=always --exclude-dir=".svn" -r "$1" . | less -R; }

to paste in your .bashrc.

  • I find this incomplete because git grep also ignores file in .gitignore. Likewise, an svn grep should not include files ignored by svn. – Warlike Chimpanzee Feb 5 '18 at 19:15

While not a perfect solution, I use the following to grep through revisions of a specific file:

for rev in `svn log FILE_TO_SEARCH | grep '^r[0-9][0-9]* ' | cut -f1 -d" "`; do svn cat -$rev FILE_TO_SEARCH 2>/dev/null | grep -q PATTERN_TO_FIND && echo $rev;done

The output is a list of revision numbers of that file that contain the string.


Svn can list the files it has under source control, and you can pipe the file list into the grep command line with xargs. In order to handle filenames with spaces you add the "-d '\n'" option to xargs. In order to silently skip directories mentioned by svn you use the "-d skip" option to grep. You may want to use egrep instead of grep, which has a more regular syntax (more like perl).

svn ls -R | xargs -d '\n' grep -d skip thingtogrepfor

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.