How to revert (roll back) to a previous revision with Subversion
When I was first starting out with Subversion, I thought there would be a revert command that took a revision as an argument and basically rolled back your application to revision X. Alas, there is a revert command in SVN, but instead of reverting to a previous revision, it works to undo any local changes you've made to your working copy.
Here, then, is a very simple, plain English explanation of how to revert to a previous version of your application in Subversion, to help anyone who may be starting out with it and is lost.
To revert to a previous version of your application (roll back changes) in Subversion, you merge the changes from your current revision back to the revision you want to revert to. So, for example, if you want to revert the trunk of your application from revision 73 to 68, you would do the following:
svn merge --dry-run -r:73:68 http://my.repository.com/my/project/trunksvn merge -r:73:68 http://my.repository.com/my/project/trunksvn commit -m "Reverted to revision 68."
Step 1 will perform a dry run and show you what the merge will produce. If you want to see exactly what changes will be applied, do a diff:
svn diff -r:73:68 http://my.repository.com/my/project/trunk
Step 2 actually performs the merge (you'd do this after you're happy with the dry run). At this point, realize what is happening: Subversion is calculating the changes between revision 73 and revision 68 of the trunk and applying them to your working copy. For the majority of the time, you will thus want your working copy to be a fully updated copy of the revision you are reverting from (in this example, revision 73).
Finally, since the merge happens on your local working copy, you need to commit it to the repository in Step 3.
The How to revert (roll back) to a previous revision with Subversion article by Aral Balkan, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial 2.0 UK: England License.

Subscribe to my blog






chris breshears
Aral, I am an SVN idiot so thanks for this. I have been using Version for the mac - http://www.versionsapp.com/ It is a free download while in beta, and super simple to use. Hoping they release it at a decent price.
June 22nd, 2008 at 4:48 pmBen
This is great! I was until recently using ZigVersion for Subversion. Going to the command line has made me more efficient with svn, but damn if a GUI doesn’t make sense for some of it’s more confusing commands.
June 22nd, 2008 at 6:00 pmBorek
That’s why good GUI tools are important - this is a no-brainer in TortoiseSVN (view change log, right-click the revision I want to roll back to and select “Revert to this revision”). It does everything necessary under the hoods.
June 22nd, 2008 at 6:51 pmpan69
These is no good GUI apps for subversion on Mac (I’m not a Mac user so I don’t really care). Even the brand new Versions seems to suck. The only sensible thing to do is to use a combination of Eclipse/Subclipse. At least that gives you consistent quality over all platforms it supports.
June 23rd, 2008 at 8:07 amMichiel van der Ros
Good to know, I’ve run into this one too. But can these commands also be executed in Eclipse, without using the terminal?
June 23rd, 2008 at 1:15 pmLuke Bayes
Hey Aral,
If you haven’t already, you might want to check out Git. It’s a fantastic version control system (created by Linus Torvalds) that truly takes the pain out of merging (and many other things too)!
I host my personal projects at GitHub which is also a great git resource for public and private repositories (I’m completely unaffiliated).
June 23rd, 2008 at 4:44 pmMike
I find it easier to use the cat command to get the version I want minus all the merging. Yes, this is an annoyance with SVN.
Something like:
$ svn stat -u build.xml
Status against revision: 17451
$ svn cat -r 17450 build.xml > build.xml
Then you can commit.
June 23rd, 2008 at 6:03 pmDavid
I started using Git recently and that is working really well for me too.
June 24th, 2008 at 2:21 pmDannyT
+1 From me for Git, I’ve not started using it but have researched it quite extensively and am very impressed with what I’ve seen and heard.
June 25th, 2008 at 10:42 amAral
Hey guys,
Thanks for the nods for Git. I did research it before starting on the Singularity site but I figured that I had enough unknowns in the project — what with me re-learning Python after several years and learning Google App Engine — that I’d limit the risk but being conservative in at least one part of it
I may transition to it once we have the first release of the site though — it does sound much better (and I like the fact that you can commit locally).
June 26th, 2008 at 9:00 amAral
Hey Mike, I’ll check out cat, thanks — it looks easier than merge if you only need to restore a single file.
June 26th, 2008 at 9:00 amMax
I was happy to find this today - thx! However, I think the syntax you want is -r73:68, not -r:73:68.
July 30th, 2008 at 7:55 pmSandro
Thanks for the post, it really helped me out. I’m using Versions.app for the Mac like someone above, but there is no merge option so these commands came in really handy.. Thanks again! Oh, and the syntax was -r 73:68 for my version of SVN.
August 20th, 2008 at 8:30 pmBoaz
Thanks for the post.
I can add that the SVN “bible”, “SVN redbook”, clearly states this usage of svn merge with fine details as well:
http://svnbook.red-bean.com/en/1.5/svn.branchmerge.basicmerging.html#svn.branchmerge.basicmerging.undo
Boaz.
September 22nd, 2008 at 8:38 amash
syntax error. change
September 26th, 2008 at 11:01 am-r:73:68
to
-r 73:68
Victor
thank you so much! You have saved me hours of reading.
October 16th, 2008 at 7:27 amVinayak
Awesome…just what i needed… Thanks
October 16th, 2008 at 7:09 pmAmrac
Merci beaucoup
November 1st, 2008 at 1:23 am(Thanks!)
El Demonio
Gracias!!!!
December 9th, 2008 at 7:50 pmThank you!!!