views:

918

answers:

5

Using SVN and/or Tortoise SVN (or any other SVN tool, really), is it possible to view the history for a specific line of a file?

Recently I've had several occurrences of coming across a line in a file and wanting to find the log entry associated with its creation (either to determine how old the line of code was, or to get a larger context for why it was added).

Right now I'm doing this by hand. I can display the log for the file, go back a ways, and see if the line in question is present. If it is, I go back further. If it isn't, I go look at a more recent revision. Repeat until the revision where the change was made is found.

Needless to say, this process is awkward at best, especially for particularly old files. Does anyone know of an automated method of accomplishing this?

+2  A: 

svn blame

Menkboy
or svn annotate, or svn praise. All depending on mood. ;-)
JesperE
+1  A: 

Use the TortoiseSVN Blame context menu option - it has a really good interface for exploring the history of individual lines.

Werg38
+1  A: 

More specifically, you can use "svn blame" with some arguments to look at specific revisions. That can be large per file... svn blame -r REV#

iterating through multiple revisions (if you working from the command line) is a quick script.

heckj
quick script please! Could do it myself but you never fail to learn from looking at other peoples code...
Ken
+1  A: 

I prefer to use svn annotate over svn blame. I wish others did as well. :-(

Andy Lester
+3  A: 

I am not sure blame alone does what the asker needs.

I have found the TortoiseSVN command "blame changes" to be handy. It runs a blame on two revisions and compares them together in the diff tool.

The result gives you what the line currently is, what it was at the targeted revision, and who modified it. This works best when you select two consecutive revisions.

You can access this by using "Show Log", right clicking on the file in the lower pane and selecting "blame changes".

Also, for anyone who does not like the term "blame", you can run "svn praise", which gives the same results. :)

Mike Miller