I am mikek's Blog

The personal blog of Mike Karthauser, who you may know from Brightstorm Limited or the internet.

Rollback with subversion

I use svn all the the time. SVN or version control is an essential part of colaborative working, and provides the means to quickly deploy only changes and allows rollback to previous versions of individual files should you commit something hooky.

The project i am working on is a migration of a app from cakephp1.1 to cakephp1.2. We’re nearly ready to deploy. Client yesterday says ok, one version for live so i delete out of the repo and the old app folder and replace it with my new one. Loverly.

So today (literally 5 mins after the delete/move the client now says he wants both versions to go live side by side. What next?

After a bit of headscratching and furious googling, the anwer is found..

From http://pontus.ullgren.com/view/SVN_by_Example#Rollback_with_subversion

To me a rollback is when you want to undo one or more commited changes. Subversion does not let you delete repository revisions so instead you need to appened a new revision at the end of the trunk/branch.

This can be achived by manualy editing all files (removing any files/directories that might have been added) and then check in the result. Another and quicker way to do it is to do a “reversed merge”, that is to merge the newer (faulty) version with the older.

$ svn merge -r 4:2 .
U testfile.txt
$ svn ci -m "Rollbacked to revision 2"
Sending testfile.txt
Transmitting file data .
Committed revision 5.
$ svn diff file:///tmp/testrepo/trunk/@2 file:///tmp/testrepo/trunk/@5
$ svn diff file:///tmp/testrepo/trunk/@4 file:///tmp/testrepo/trunk/@5
Index: testfile.txt
--- testfile.txt (revision 4)
+++ testfile.txt (revision 5)
@@ -1,3 +1 @@
Added file in revision 2
-Added a new line in rev 3
-Added yet another line in rev 4

Result, easy merged svn. No kittens killed


Filed under: development,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

mikek on twitter

%d bloggers like this: