144

Is there a way to perform a full text search of a subversion repository, including all the history?

For example, I've written a feature that I used somewhere, but then it wasn't needed, so I svn rm'd the files, but now I need to find it again to use it for something else. The svn log probably says something like "removed unused stuff", and there's loads of checkins like that.

Edit 2016-04-15: Please note that what is asked here by the term "full text search", is to search the actual diffs of the commit history, and not filenames and/or commit messages. I'm pointing this out because the author's phrasing above does not reflect that very well - since in his example he might as well be only looking for a filename and/or commit message. Hence a lot of the svn log answers and comments.

2
  • 6
    Apache Subversion 1.8 accepts --search argument for svn log command. See my answer at stackoverflow.com/a/17473516/761095
    – bahrep
    Jul 4, 2013 at 15:06
  • 3
    svn log --search does not perform a full text search as required by @rjmunro, but only searches author, date, log message and list of changed paths.
    – zb226
    Apr 15, 2016 at 10:25

16 Answers 16

73
git svn clone <svn url>
git log -G<some regex>
12
  • 4
    Be advised, this can take a while depending on the size of your repository. For me it took more than an hour.
    – user247702
    Aug 7, 2015 at 16:31
  • 33
    I downvoted this solution since converting a big SVN repository to GIT is often not feasible or would take much too long. It's like recommending Java when having a question about a C# language construct.
    – ooxi
    Mar 11, 2016 at 7:31
  • 3
    You may need to install an additional package for this command. On Ubuntu, you want to apt-get install git-svn.
    – nedned
    Mar 23, 2016 at 23:53
  • 7
    Doesn't "svn log --verbose --diff | grep ..." buy your roughly the same functionality without having to use git?
    – lyte
    Jul 6, 2016 at 5:33
  • 3
    @lyte It roughly is the same functionality. It is very good in so far you work with svn alone. I find this idea to utilize git to search for commits ridiculous. The trouble starts when you want to see more than just the line containing the term you searched for. grep can print a number of lines before the finding and after but you never know how many lines you need (to find the revision number at the top or the whole comment to the bottom). The output is hard to read. Aug 23, 2017 at 10:42
45

Update April, 2022

VisualSVN Server 5.0 comes with a new full-text search feature that allows you to search through the contents and history of your repositories in the web interface. Try out the feature on the demo server.


Old answer

svn log in Apache Subversion 1.8 supports a new --search option. So you can search Subversion repository history log messages without using 3'rd party tools and scripts.

svn log --search searches in author, date, log message text and list of changed paths.

See SVNBook | svn log command-line reference.

3
  • 7
    Handy, but not full-text search. I'm sticking with the git-svn answer :-)
    – rjmunro
    Jul 4, 2013 at 19:10
  • 4
    Not that at the moment svn repos on googlecode are still running on svn 1.6... see: code.google.com/p/support/wiki/…? But, updating your client to 1,8 (and svn upgrade of any checked out repo) will allow you to use svn log --search on the repo... Aug 15, 2014 at 11:05
  • The working copy needs all the updates but this command lists the whole change including revision number, changed files and comment. How is it not full-text? Aug 23, 2017 at 10:50
24

If you are running Windows have a look at SvnQuery. It maintains a full text index of local or remote repositories. Every document ever committed to a repository gets indexed. You can do google-like queries from a simple web interface.

2
21

I'm using a small shellscript, but this only works for a single file. You can ofcourse combine this with find to include more files.

#!/bin/bash
for REV in `svn log $1 | grep ^r[0-9] | awk '{print $1}'`; do 
  svn cat $1 -r $REV | grep -q $2
  if [ $? -eq 0 ]; then 
    echo "$REV"
  fi 
done

If you really want to search everything, use the svnadmin dump command and grep through that.

4
  • I had to remove the "r" from revisions numbers with: awk '{print substr($1,2,length($1))}' and remove the grep "-q" option, to actually show the matches.
    – Hugo
    Dec 6, 2010 at 13:57
  • strings myDump.txt | grep "turtle fwd 10"
    – jedierikb
    Jul 14, 2012 at 2:31
  • 3
    And this is why we embrace git. Oct 17, 2013 at 19:27
  • might want to do last grep -i for ignore case and drop the -q to actually see the row that matched
    – Belun
    Jul 22, 2016 at 11:46
13

The best way that I've found to do this is with less:

svn log --verbose | less

Once less comes up with output, you can hit / to search, like VIM.

Edit:

According to the author, he wants to search more than just the messages and the file names. In which case you will be required to ghetto-hack it together with something like:

svn diff -r0:HEAD | less

You can also substitute grep or something else to do the searching for you. If you want to use this on a sub-directory of the repository, you will need to use svn log to discern the first revision in which that directory existed, and use that revision instead of 0.

3
  • 6
    That's not full text searching, it's searching the logs and filenames.
    – rjmunro
    Sep 7, 2008 at 14:09
  • If that is the case, then you need to use more expressive commit logs. If you want to grep the difference between revisions, that is whole other ball of wax. And I personally do not know a way to do that.
    – Jack M.
    Mar 23, 2009 at 18:11
  • > svn diff -r0:HEAD > log > less log is my choice on windows. Thanks
    – kingoleg
    Apr 11, 2016 at 14:57
10
svn log -v [repository] > somefile.log

for diff you can use the --diff option

svn log -v --diff [repository] > somefile.log

then use vim or nano or whatever you like using, and do a search for what you're looking for. You'll find it pretty quickly.

It's not a fancy script or anything automated. But it works.

3
  • AFAICS, That will search commit messages, not the actual diffs.
    – rjmunro
    Oct 14, 2015 at 16:21
  • Then use svn log -v --diff [repository] > somefile.log
    – JREN
    Oct 15, 2015 at 6:06
  • or just pipe through grep as in zednight's answer
    – giles
    Oct 8, 2020 at 18:00
9

I have been looking for something similar. The best I have come up with is OpenGrok. I have not tried to implement it yet, but sounds promising.

1
  • I've been using OpenGrok for several months, it rocks. Sep 29, 2008 at 16:16
6

While not free, you might take a look at Fisheye from Atlassian, the same folks that bring you JIRA. It does full text search against SVN with many other useful features.

http://www.atlassian.com/software/fisheye/

2
  • 1
    Fisheye's pretty good. As you say, not free, but the <=10 committer license is only $10/year.
    – Jason S
    Nov 30, 2010 at 18:47
  • Currently, 5 users is $10, BUT at only 10 users it jumps to $1,000 ! Jun 9, 2016 at 10:19
5

I just ran into this problem and

svnadmin dump <repo location> |grep -i <search term>

did the job for me. Returned the revision of the first occurrence and quoted the line I was looking for.

1
  • 1
    Works only locally and will take a lot of time if a repository is large.
    – bahrep
    Jul 4, 2013 at 15:13
4

I was looking for the same thing and found this:

http://svn-search.sourceforge.net/

4

Use unix utility like grep:

svn log -l <commit limit> --diff | grep -C <5 or more lines> <search message>

or you can save the result of the svn log somewhere, then search through it

1
  • 2
    add --diff to that to get text search of the changes
    – giles
    Oct 8, 2020 at 17:59
2

I don't have any experience with it, but SupoSE (open source, written in Java) is a tool designed to do exactly this.

1

I usually do what Jack M says (use svn log --verbose) but I pipe to grep instead of less.

2
  • 6
    That's not full text searching, it's searching the logs and filenames.
    – rjmunro
    Sep 7, 2008 at 14:07
  • That is what I usually end up doing, but I've found that with less you can actually see the revision, date, etc instead of just the line in the comment. That is usually what I'm looking for anyway.
    – Jack M.
    Mar 23, 2009 at 18:10
1

I wrote this as a cygwin bash script to solve this problem.

However it requires that the search term is currently within the filesystem file. For all the files that match the filesystem grep, an grep of all the svn diffs for that file are then performed. Not perfect, but should be good enough for most usage. Hope this helps.

/usr/local/bin/svngrep

#!/bin/bash
# Usage: svngrep $regex @grep_args

regex="$@"
pattern=`echo $regex | perl -p -e 's/--?\S+//g; s/^\\s+//;'` # strip --args
if [[ ! $regex ]]; then
    echo "Usage: svngrep \$regex @grep_args"
else 
    for file in `grep -irl --no-messages --exclude=\*.tmp --exclude=\.svn $regex ./`;     do 
        revs="`svnrevisions $file`";
        for rev in $revs; do
            diff=`svn diff $file -r$[rev-1]:$rev \
                 --diff-cmd /usr/bin/diff -x "-Ew -U5 --strip-trailing-cr" 2> /dev/null`
            context=`echo "$diff" \
                 | grep -i --color=none   -U5 "^\(+\|-\).*$pattern" \
                 | grep -i --color=always -U5             $pattern  \
                 | grep -v '^+++\|^---\|^===\|^Index: ' \
                 `
            if [[ $context ]]; then
                info=`echo "$diff" | grep '^+++\|^---'`
                log=`svn log $file -r$rev`
                #author=`svn info -r$rev | awk '/Last Changed Author:/ { print $4 }'`; 

                echo "========================================================================"
                echo "========================================================================"
                echo "$log"
                echo "$info"
                echo "$context"
                echo
            fi;
        done;
    done;
fi

/usr/local/bin/svnrevisions

#!/bin/sh
# Usage:  svnrevisions $file
# Output: list of fully numeric svn revisions (without the r), one per line

file="$@"
    svn log "$file" 2> /dev/null | awk '/^r[[:digit:]]+ \|/ { sub(/^r/,"",$1); print  $1 }'
1
-2

In case you are trying to determine which revision is responsible for a specific line of code, you are probably looking for:

svn blame

Credit: original answer

-3

I came across this bash script, but I have not tried it.

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