Is it possible to see the history of changes to a particular line of code in a Subversion repository?
I\'d like, for instance, to be able to see when a particular st
In the TortoiseSVN client there is a very nice feature that lets you:
The second feature does what it says - it shows the annotated revision preceding the last modification to the line. By using this feature iteratively, you can trace back through the history of a particular line.
A start is the command svn blame (or annotate,praise). It will show you when a line of code was last modified and by whom it was modified. e.g.:
4564 wiemann # $Id$
4564 wiemann # Author: David Goodger <goodger@python.org>
778 goodger # Copyright: This module has been placed in the public domain.
217 goodger
The key here is how much history is required. As others have pointed out, the short answer is: svn blame
(see svn help blame
for details). If you're reaching far back in history or dealing with significant changes, you will likely need more than just this one command.
I just had to do this myself, and found this (ye ole) thread here on SO. Here's what I did to solve it with just the CLI
, specifically for my case where an API had changed (e.g. while porting someone's far outdated work (not on a branch, arrgh!) back into a feature branch based off of an up-to-date trunk). E.g. function names had changed enough to where it wasn't apparent which function needed to be called.
The following command allowed me to page through commits where things had changed in the file "fileName.h" and to see the corresponding revision number (note: you may have to alter the '10' for more or less context per your svn log text).
svn log | grep -C 10 "fileName.h" | less
This results in a list of revisions in which this file was modified.
Then it was a simple matter of using blame
(or as others have pointed out, annotate
) to narrow down to the revisions of interest.
cd trunk
svn blame fileName.h@r35948 | less
E.g. found the revision of interest was 35948.
Having found the revision(s) of interest via blame, a diff can be produced to leverage the SVN tool.
svn diff -r35948:PREV fileName.h
Having a visual diff made it much easier to identify the old API names with the newer/updated API names.
I'd usually:
svn blame FILE
first.Do another query with the -r
argument:
svn blame FILE -r 1:REV
If you use Emacs, the built-in package vc
can do this.
vc-annotate
with either M-x vc-annotate
or C-xvg.svn blame
.vc-annotate-revision-previous-to-line
) will navigate to the revision before the revision at the line you're on.svn annotate
The AKA SVN Blame from TortoiseSVN.