Get file list of last N commits in Subversion Get file list of last N commits in Subversion shell shell

Get file list of last N commits in Subversion


To get the last N commits, use the --limit or -l flag to svn log. Alternatively, you can also limit your log entries by revision number and/or by date.

To get the files changed, you need to use the -v (or --verbose) flag.

And to suppress the log text, you need to use the -q (or --quiet) flag.

Putting it all together, to get (for example) all files changed since the beginning of May 2014 (in easy to parse format), you could do this:

svn log --quiet --verbose --revision {2014-05-01}:HEADsvn log -q -v -r {2014-05-01}:HEAD

or to get the same info for the last 10 commits, no matter when they happened:

svn log --quiet --verbose --limit 10svn log -q -v -l 10


There is no simple, single Subversion command that will give you that information.

There are a few loose ends here:

  • Do you mean the last few revisions of the directory (project) you're in, or of the entire repository. If you're talking about the entire repo, you could get the latest revision, and then subtract out the number you want. If you're talking about the individual project, it gets a lot tougher.

  • I take it you want a list that doesn't contain duplicates.

  • What about files that were added or deleted? How do you want to count those?

This isn't as difficult as it seems, but you'll have to write your own script to do this. The svn log takes a --xml parameter and will return the log in XML format. The format looks like this:

$ svn log -v --xml $REPO<?xml version="1.0" encoding="UTF-8"?><log><logentry    revision=...><author>...</author><date>...</date><paths><path   ....   ....   action=".">...name of file...</path><path ...</paths><msg>.....</msg></logentry><logentry   ....   ....

Even if you don't parse the XML itself, you could easily use the XML output to get the information you need. Count the number of <logentry lines until you get the number or entries you want. Use the <path to mark the beginning of theelement, and when you see the closing>, you know that the rest of the line till the` is the name of the file. Store these files in a hash variable keyed by the name of the file.

A script in Python or Perl should be pretty easy to do.


You tagged your question "shell" so chances are you are not on Windows, but on the off-chance you are, one can do almost anything in one line of PowerShell (substitute your value of "n" for the "99" in this recipe):

PS> Get-SvnLog |Select -First 99 -ExpandProperty Paths |% { ([xml]$_).SelectNodes("//path/text()").Value } |Sort -Unique

You can see the API for Get-SvnLog in my open source bookshelf, which includes more than 20 other examples of reports you can get. Open the PowerShell "book" and go to SvnTools. Download the code here.