go to it

svn admin

We:EA 2019. 1. 9. 11:40

Delete file, directory or revision from Subversion history

Removing data from Subversion history is a frequent topic, raising many questions. Meanwhile, the infamous obliterate command is a perfect exemple of vaporware.
So now, what can you actually DO?
This post is trying to compile all possible use cases.

Before you start

Deleting content from SVN is pretty simple. That does not mean it's painless. If you're used with ClearCase rmelem and rmver commands, well, just forget it. Performing such operations in Subversion requires having a terminal access to the server, and a couple of spare hours if the repository is big. For monster repositories, schedule this on a week-end.

Generic procedure

1. Dump your Subversion repository: svnadmin dump
2. Filter that dump to remove unwanted elements: svndumpfilter (exclude or include)
3. Create a new repository: svnadmin create 
4. Reload the filtered dump into a new repository: svnadmin load

Note: one usually wants to replace the old repository with the filtered one. The procedures below don't take that into account. If you intend to do so, basic recommendations are to:
  • Save a backup of the original repository
  • Delete the repository
  • Create a new repository with the same name than the old one

Delete old revisions from a repository

Assumptions:
The latest revision of the repository is 1000.
You want to delete revisions from 1 to 500.

1. Dump wanted revisions from the repository
svnadmin dump /data/myrepo -r501:1000 > myrepo.dump

2. Create the new repository
svnadmin create /data/mynewrepo

3. Load the filtered dump into the new repository
svnadmin load /data/mynewrepo < myrepo.dump

Delete files or directories from a repository

1. Dump the repository
svnadmin dump /data/myrepo > myrepo.dump

2. Filter the elements
  • You may want to remove some elements:
    svndumpfilter exclude unwanted/elements < myrepo.dump > myrepo-filtered.dump
  • Or keep some of them:
    svndumpfilter include wanted/elements < myrepo.dump > myrepo-filtered.dump
  • Using a pattern:
    svndumpfilter exclude --pattern '*.ext' < myrepo.dump > myrepo-filtered.dump

3. Create the new repository
svnadmin create /data/mynewrepo

4. Load the filtered dump into the new repository
svnadmin load /data/mynewrepo < myrepo-filtered.dump

Notes: Subversion is referencing a file or a directory by its path and name. If an element was renamed or moved, svndumpfilter exclude file-newname won't delete the whole history of the file but only references matching the exact path and name file-newname. In this exemple file-oldname will still be present in the repository history after the operation.
You can work around this by developping a script using svn log -v file-newname, get the old name and filter it as well.  

Delete a single revision from history

Deleting a single revision from history is a risky operation which can easily fail. Think twice before proceeding, maybe you're just trying to restore a specific revision as the latest? In that case, svn merge -r:last_rev:restored_rev is the answer. Or maybe you want to delete specific files that shouldn't have been added in that revision? Then refer to section "Delete files or directories from a repository" above.
If you still want to remove an old revision for any good reason, you can attempt to skip that revision during a dump / load operation.
Note that if you skip revisions in the load, next revisions will be renumbered.

Assumptions:
The latest revision of the repository is 1000.
You want to delete revision 500.

1. Dump wanted revisions of the repository
svnadmin dump /data/myrepo -r1:499 > myrepo-1.dump
svnadmin dump /data/myrepo -r501:1000 --incremental > myrepo-2.dump 

2. Create the new repository
svnadmin create /data/mynewrepo

3. Load the filtered dump into the new repository
svnadmin load /data/mynewrepo < myrepo-1.dump
svnadmin load /data/mynewrepo < myrepo-2.dump 

Note: As mentioned before, this operation can easily fail. Here is a simple failure exemple.

Assumptions:
1. You added a new file in revision 6
2. You modified that file in revision 7 or after
3. You want to delete revision 6 following the procedure described here
When trying to incrementaly add revision 7 over 5, you would get the following error message and load would abort:

<<< Started new transaction, based on original revision 7
* editing path : new-file ...svnadmin: E160013: File not found: transaction '5-5', path 'new-file'


Delete a range of revisions from history

Deleting a range of revisions would use the same procedure than for a single one. However, as deleting only one revision may fail, the risk of failure increase with the number of revisions in the range.