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.

This entry was posted in Uncategorized. Bookmark the permalink.

16 Responses to Delete parts of subversion history

  1. Joshua L. Davis says:

    Thanks!

  2. Darren G says:

    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″

  3. Pingback: House of Code

  4. abhilash says:

    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.

  5. Rob says:

    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.

  6. shuai.liu says:

    [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?

  7. Rob says:

    Well you could just dump the new repo. Delete both of them and then restore the repo to the original name.

  8. nirs says:

    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’

  9. Sean says:

    Awesome! Thanks :)

  10. ccm says:

    -r9000:HEAD is probably better.

  11. john says:

    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.

  12. Angel says:

    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! =)

  13. Rob says:

    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.

  14. Quattro says:

    try searching for svndumpfilter, it will help you remove offending paths from your complete tree

  15. Pingback: Subversion (SVN): Permanently remove files from repository (history) « Christosoft Blog

  16. ricki says:

    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 *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">