Remove a commit from a svn repository

April 28th, 2007

Bad things(tm) happen. From time to time you’ll find yourself with a problem that cannot be fixed simply by reverting to a previous revision.

In fact, even if you commit an old version of the file, the data that you previously committed will still be there: this is all what VCS (Version Control Systems) are about: maintaining an history of what has been done with the code.

Sometimes this is desiderable, sometimes it is not.
Say that you just committed a security fix to your repository, something that you were not supposed to disclose immediately.
Or say that by mistake you committed some code whose licence doesn’t allow to be merged with your code.

There is an easy way out of this problem, but it requires filesystem access to the SVN repository location.
Suppose that your repository is installed under /var/lib/svn/myrep, the latest rev. is 100 and you want to completely delete from your repository all revisions greater than 95. Here is how to proceed:

svnadmin dump /var/lib/svn/myrep -r 1:95 --incremental >/tmp/svn.dump
mv /var/lib/svn/myrep /var/lib/svn/myrep-BACKUP-$(date +%s)
svnadmin create /var/lib/svn/myrep
svnadmin load /var/lib/svn/myrep </tmp/svn.dump

Hope it was helpful! Feel free to contact me if you have any questions.

Note: Thanks to Alan B. for pointing out that recent svn versions don’t support leaving the starting revision empty, like this: “-r :95″

Share

Add a comment

You must be logged in to post a comment.