I would like to do the following using svn
: Search in a file for a certain string content across the revision history? Is this possible>? How do I best go about it?
Do I come up with a script using svn cat -r1
and grep
or is there some better method?
Asked
Active
Viewed 143 times
0

stdcerr
- 13,725
- 25
- 71
- 128
1 Answers
1
Svn has no direct support for this.
If it's only one file this will work, albeit slowly.
svn log -q <file> | grep '^r' | awk '{print $1;}' | \
xargs -n 1 -i svn cat -r {} <file> | grep '<string>'
Fill in <file>
and <string>
A for
loop will also work so you can print the matching file/revision if desired.
Using a for
loop to have some more output control (this is bash):
#!/bin/env bash
f=$1
s=$2
for r in $(svn log -q "$f" | grep '^r' | awk '{print $1;}'); do
e=$(svn cat -r $r "$f" | grep "$s")
if [[ -n "$e" ]]; then
echo "Found in revision $r: $e"
fi
done
This takes two arguments: the (path to) the file to search and the string to search for in the file.

Atafar
- 697
- 7
- 10
-
Thanks for this, I was looking for something along these lines, how would you recommend I print out the revision number for every match? – stdcerr May 27 '15 at 20:37