Tutorial :How to find out which revision contained a certain line in SVN


We would like to trace removal of a single line in a certain file amongst the many revisions to that file in SVN.

I tried looking at various revisions / diffs to see when it was removed, but was unable to find the offending revision. How do we do this using a svn command?


If you're on Linux and you know in which file to look you can use that shell script to output all the revision of that file.

#!/bin/bash  svn log "$1" -q | grep -oE r[0-9]+ | xargs -t -n1 -r -d '\n' svn cat "$1" -r  

Pass a working copy file name or repository URL as a parameter to this script.

If everything else fail and you're doing regular dumps using svnadmin dump without the --incremental switch you could grep for the text in the latest dump file.

Non-incremental dumps contain the full text for each revision of every files.


nedbatchelder.com made a python script for exactly that purpose.


I know this isn't pretty, but it would be relatively quick: I would suggest just manually going through the svn revisions for that file using a "human" binary search. If you have 2000 revisions to go through, you would only need to physically look at 12 revisions to narrow it down to the offending revision.

Let's say the line was added in r1000 and the latest revision is r3000. Then check r2000, if the line still exists there, pick a revision halfway between r2000 and r3000 (ie r2500), otherwise pick a revision halfway between r1000 and r2000 (ie r1500). Just continue using this manual search algorithm to narrow it down. With a window of 2000 revisions, you should get it within 12 iterations. (2000, 1000, 500, 250, 125, 64, 32, 16, 8 ,4, 2, 1, bingo!)

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »