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?
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.