tags:

views:

1049

answers:

5

I know that I can svn diff -r a:b repo to view the changes between the two specified revisions. What I'd like is a diff for every revision that changed the file. Is such a command available?

+1  A: 

You could use git-svn to import the repository into a Git repository, then use git log -p filename. This shows each log entry for the file followed by the corresponding diff.

Greg Hewgill
Install git, create a git repository, use a git command? The question was tagged and asked about Subversion.
Ken Gentle
I use git as a Subversion client with git-svn. This is how I would do the log+diff operation against a Subversion repository. Git has some really excellent tools for repository viewing, it's not such an outlandish idea.
Greg Hewgill
+2  A: 

As far as I know there is no built in svn command to accomplish this. You would need to write a script to run several commands to build all the diffs. A simpler approach would be to use a GUI svn client if that is an option. Many of them such as the subversive plugin for Eclipse will list the history of a file as well as allow you to view the diff of each revision.

D-Rock
+2  A: 

Start with

svn log -q file | grep '^r' | cut -f1 -d' '

That will get you a list of revisions where the file changed, which you can then use to script repeated calls to svn diff.

+9  A: 

There's no built-in command for it, so I usually just do something like this:

#!/bin/bash

# history_of_file
#
# Outputs the full history of a given file as a sequence of
# logentry/diff pairs.  The first revision of the file is emitted as
# full text since there's not previous version to compare it to.

function history_of_file() {
    url=$1 # current url of file
    svn log -q $url | grep -E -e "^r[[:digit:]]+" -o | cut -c2- | sort -n | {

#       first revision as full text
        echo
        read r
        svn log -r$r $url@HEAD
        svn cat -r$r $url@HEAD
        echo

#       remaining revisions as differences to previous revision
        while read r
        do
            echo
            svn log -r$r $url@HEAD
            svn diff -c$r $url@HEAD
            echo
        done
    }
}

history_of_file $1
bendin
I've never seen that "piping into the braced block" trick before. Neat.
Thank you very much for this script. Its really useful!
Alex. S.
wow, for once a snippet on SO just works! Thank you!
deadprogrammer
+1  A: 

Slightly different from what you described, but I think this might be what you actually need:

svn blame filename

It will print the file with each line prefixed by the time and author of the commit that last changed it.

ngn