History of changes to a particular line of code in Subversion

Viewed 42942

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 statement was added or when that statement was changed, even if its line number is not the same any more.

11 Answers

I don't know a method for tracking statements through time in Subversion.

It is simple however to see when any particular line in a file was last changed using svn blame. Check the SVNBook: svn blame reference:

Synopsis

svn blame TARGET[@REV]...

Description

Show author and revision information in-line for the specified files or URLs. Each line of text is annotated at the beginning with the author (username) and the revision number for the last change to that line.

In the TortoiseSVN client there is a very nice feature that lets you:

  • blame a file, displaying the last change for each line (this is standard)
  • "blame previous revision", after clicking on a particular line in the above view (this is the good one)

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.

svn blame shows you which checkin modified any line in a file the last time.

This works on old revisions too.

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 

If you use Emacs, the built-in package vc can do this.

  1. Navigate to the file in question.
  2. Run the command vc-annotate with either M-x vc-annotate or C-xvg.
  3. Each line will show up with its revision, like a normal svn blame.
  4. Pressing a (vc-annotate-revision-previous-to-line) will navigate to the revision before the revision at the line you're on.
Related