Tim Hatch

Weblog | Photos | Projects | Panoramas | About

Howto: svn commit rollback 18 Apr, 2006

This describes how to fix an svn repository after accidentally committing a file with a password in it:

Yes, this happened to me. Today. I didn’t look at the files before committing to my public repository, and had to fix it quickly. These are the steps to undo the last revision. First, the easy way (if using fsfs backend):

The first thing you need to do is stop the server. Anyone who checks out the repository while it contains the soon-to-be-deleted rev will be hosed and have to check it out again from scratch. This includes the WC you committed from, so go ahead and move that out of the way.

  • Go into the svn repository using cd
  • Edit db/current and decrement the first number. That's the tip revision.
  • Move db/revs/$BADREV and db/revprops/$BADREV out of the way, so when someone does commit that rev it won't have issues
  • Run trac-admin resync and/or restart Apache, as necessary

And now the hard way, if you're using the bdb backend (because this way makes more sense than hacking it directly):

The first thing you need to do is stop the server. Anyone who checks out the repository while it contains the soon-to-be-deleted rev will be hosed and have to check it out again from scratch. This includes the WC you committed from, so go ahead and move that out of the way.

tim@client# mv workingcopy workingcopy_bad

root@server# /etc/init.d/apache2 stop
* Stopping web server: Apache2
root@server# cd /var/svn
root@server# svnadmin dump reponame > svn.dump
root@server# vim svn.dump (delete the offending revision in its entirety)
root@server# mv reponame reponame_bad
root@server# svnadmin create reponame
root@server# svnadmin load --force-uuid reponame < svn.dump
root@server# chown -R www-data:www-data reponame
root@server# /etc/init.d/apache2 start
root@server# trac-admin /path/to/repo resync

tim@client# svn co http://example.com/path/to/repo

That’s it... once you’ve got your WC clean, make the changes but this time watch out for passwords and recommit the changes you made the last time.

Updated 2007-07-27 for better fsfs instructions, suggested by Eric below (and finally verified as working by me).