How to export changed files between two SVN revisions

Here is a great step by step tutorial which do this with TortoiseSVN's Compare revisions and Export selection to... functions:

http://www.electrictoolbox.com/tortoisesvn-exporting-changed-files/


As far as I know, svn does not provide such a feature. But you may write a simple c# program using SharpSVN to do it. Here is a sample that you can use. In this sample, I am getting the whole changed file from revision 100 to 200.

using SharpSvn;
using System.IO;
using System.Collections.ObjectModel;
using Microsoft.VisualBasic;

namespace SvnDiffExporter
{
    class Program
    {
        static void Main(string[] args)
        {
            SvnClient client = new SvnClient();
            SvnRevisionRange range = new SvnRevisionRange(100, 200);
            MemoryStream result = new MemoryStream();

            Collection<SvnLogEventArgs> items;
            SvnLogArgs logargs = new SvnLogArgs(range);
            client.GetLog(@"e:\Artifacts", logargs, out items);

            int i = 0;
            string [] path = new string[255];
            foreach (SvnLogEventArgs ar in items)
            {
                foreach (SvnChangeItem changeitem in ar.ChangedPaths)
                {
                    if (changeitem.Action != SvnChangeAction.Delete)
                    {
                        path[i] = changeitem.Path;
                        i++;
                    }
                }
            }

            string localpath = @"c:\data";
            foreach (string str in path)
                client.Export(str, localpath);
        }
    }
}

I created a batch file that will work to export the files changed between revisions.

@echo off

FOR /F "tokens=1,2" %%I IN ('svn diff --summarize -r %1') DO (
    IF NOT %%I == D (
        IF NOT EXIST %2\%%J\.. mkdir %2\%%J\..

        svn export --depth empty -q --force %%J %2\%%J
        echo %2\%%J
    )
)

To use it you just specify the revision or revision range on the command line and a destination for exported files.

C:\YourRepository>svnexport.bat 1:10 C:\Export

Tags:

Svn