Subversion commands

Native commands

  • Revert current local folder to revision 666:
    svn merge -rHEAD:666 ./
    
  • Create an empty repository:
    svnadmin create ./my-repo
    
  • Dump a repository (a sure way to migrate a subversion repository from one version to another):
    svnadmin dump ./my-repo > ./my-repo.dmp
    
  • Migrate a remote Subversion repository without creating an intermediate dump file:
    ssh -C user@myserver.com "svnadmin dump /home/user/my-repo" | svnadmin load /home/user2/my-new-repo
    
  • Launch a standalone Subversion server listening on port 3690 and serving all repositories located in ./repos/:
    svnserve --daemon --listen-port 3690 --root ./repos/
    

Local working copy hacking

  • Recursive and case insensitive content search on non-binary files from the current folder, while ignoring .svn folders and their content:
    find ./ -type f -not -regex ".*\/.svn\/.*" -exec grep -Iil "string to search" {} \;
    
  • Same thing as above but with an alternative approach (that don’t work with large folder content):
    grep -Ii "string to search" $(find . | grep -v .svn)
    

    Other alternative: use ack.

  • Use sed to replace text in all files except in subversion metadatas:
    find ./ -type f -not -regex ".*\/.svn\/.*" -print -exec sed -i 's/str1/str2/g' "{}" \;
    
  • Use svn delete to remove all files containing a tilde in their name without touching local subversion metadatas:
    find -type f -not -regex ".*\/.svn\/.*" -name "*˜*" -print -exec svn delete "{}" \;
    
  • In a repository structure containing sub-projects (thinks of Plone’s collective repository as an example), get the list of all folders in all trunks, while ignoring subversion metadata folders:
    find ./ -type d -regex ".*\/trunk\/?.*" -not -regex ".*\/.svn\/?.*" -print
    
  • Similarly to the command above, replace all occurrences of the string @coolcavemen.fr by @coolcavemen.com in all trunk subfolders while ignoring .svn content:
    find ./ -type f -regex ".*\/trunk\/.*" -not -regex ".*\/.svn\/.*" -print -exec sed -i 's/@coolcavemen\.fr/@coolcavemen\.com/g' "{}" \;
    
  • Set a svn property to ignore all .mo files during commit in every folder of our local working copy containing .po files:
    find ./ -type f -name "*.po" -regex ".*\/trunk\/.*" -not -regex ".*\/.svn\/.*" -printf "%h\n" | uniq | xargs svn propset "svn:ignore" "*.mo"
    

How-to Backup / Mirror a public SVN repository

In this little how-to I will show you how to backup a public SVN repository thanks to SVK, a tool build upon SVN framework that add decentralized capabilities.

First, create a local repository:

svk mirror //local https://username@svn.kde.org/home/kde

SVK will ask you to create a new repository. Tell it you want so:

Repository /home/user/.svk/local does not exist, create? (y/n) y

Then, sync the remote repository with the local one:

svk sync //local

That’s all !

To update your locale repository with the latest set of changes from the remote one, just run the previous command from time to time.

Now you can play with your local repository (/home/user/.svk/local in this exemple) as if it was a normal SVN repository !

Update: If you want to generate a vanilla SVN dump out of your SVK local mirror, as suggest by Thomas Mølhave in his “Remote Backup Of A Subversion (svn) Repository” blog post, use svnadmin:

svnadmin dump -r2:HEAD ~/.svk/local > my-repository-dump