Delete parts of subversion history

When you decide to move a svn repository to the public it might be necessary to remove older versions from history.

For example, lets say your repository is at version 10000. However up until version 9000 you where not considering going open source. But once you did you cleaned up the code. However the old dirty code is still in svn history.

You don’t want to loseWeight Exercise all of the history, just everything below version 9000.

This is how you do it.

svnadmin dump /path/to/current/repo -r9000:10000 > svn.dump
svnadmin create /path/to/new/repo
svnadmin load /path/to/new/repo < svn.dump

Poof! Version 9000 and below are gone. The repository is now at version 1000.

16 thoughts on “Delete parts of subversion history”

  1. This helped me. I am runing SVN on a windows serverSince I envisage doing this on a regular (but infrequent) basis I thought I would throw together a batch file to help me along with it. The text of it is below if anyone is interested:

    @echo off
    REM check inputs

    if %1x==x goto abortusage
    if %2x==x goto abortusage

    REM check Path

    if not exist “%1″ set msg=”The Path to the repository (%1) does not exist!”
    if not exist “%1” goto abortusage

    REM Delete any older dump temp files
    if exist “.\tmp” rd “.\tmp” /S /Q

    REM get the last version number
    svnlook youngest “%1” > mrr.txt
    REM read the line from the MRR file
    for /F %%f IN (.\mrr.txt) DO set svnlast=%%f

    echo ————————–
    echo Last Revision was %svnlast%
    echo ————————–
    REM Dump
    svnadmin dump “%1” -r%2:%svnlast% > svn.dump

    REM copy the currnt live to a tmp
    mkdir tmp
    XCOPY “%1\*.*” ./tmp

    REM delete original
    rd “%1” /S /Q

    REM create a “new” repository
    svnadmin create “%1”

    REM reload
    svnadmin load “%1”

  2. Pingback: House of Code
  3. Hai,
    I need to delete particular revision from history. Actually I have mistakenly tagged in worng folder. I have deletd the folder from svn. But in history still its showing. How can I delete that history.
    eg: revision no. 224876

    Please reply. It will be very helpful.

  4. You will need to do 2 dumps in this case I think.

    svnadmin dump /path/to/current/repo -r1:224875 > svn.dumpa
    svnadmin dump /path/to/current/repo -r224876:HEAD > svn.dumpb
    svnadmin create /path/to/new/repo
    svnadmin load /path/to/new/repo < svn.dumpa svnadmin load /path/to/new/repo < svn.dumpb Your svn # numbers will be off by one. To avoid this do a blank commit after loading dumpa. Note: I have not tried this.

  5. [Re:Rob ]
    if I do this.
    There is another path of the repo,/path/to/new/repo is different with /path/to/current/repo , but i want to keep the same path.
    How can I do that?

  6. This does not work – loading works only on empty directory.

    When you try to load the second part of the dump, you get this error:

    <<< Started new transaction, based on original revision 1989
    * editing path : … done.
    svnadmin: File already exists: filesystem ‘/var/local/svn/repository/cleaned/db’, transaction ‘1988-5’, path ‘foo’

  7. Thanks!

    I’d recommend starting with 9001 รขโ‚ฌโ€œ then the new id is the old one minus 9000, not minus 8999 as it were with 9000. So it’s easier to map revision numbers in case you need it some time.

  8. Hello,

    I need to delete older versions , say <2000, but i want to mantain current version numbers, so last version is 2049 not 49.

    I’ve tried to go through your steps but the revision numbers of the new repo starts at 1 and finish at 49 (not 2049 which i need)

    Can it be done?

    Thanks! =)

  9. I’ve done this too. Not sure if this is the best way, but before I loaded the dump file I added in X number of blank changes. (I wrote a script that touched a file and then did a commit X number of times) X would be 2000 in your case.

    Again, not sure if there is a better way.

  10. it’s not quite as simple as “poof” and it’s all gone…

    There is a massive side effect which is:
    1. all branches/tags that are copies in the original become files in their own right
    2. as a result of 1, the dump file can become MASSIVE

Leave a Reply

Your email address will not be published. Required fields are marked *