In 2008, over one thousand people experienced the world’s first virtual web conference. Together, we created a new type of conference that is environmentally-friendly, affordable, and interactive.

In 2009, we are going to take it one step further.


How to revert (roll back) to a previous revision with Subversion

You would think that reverting to a previous version of your application would be one of the key use cases for a version control system like Subversion and that it would be trivial to do, but it's actually not intuitive at all.

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:

  1. svn merge --dry-run -r:73:68 http://my.repository.com/my/project/trunk
  2. svn merge -r:73:68 http://my.repository.com/my/project/trunk
  3. svn 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.

Post Metadata

Date
June 22nd, 2008

Author
Aral

Category


18 Comments

  1. 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.



  2. Ben

    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.


  3. 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.



  4. pan69

    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.


  5. Good to know, I’ve run into this one too. But can these commands also be executed in Eclipse, without using the terminal?


  6. 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).



  7. Mike

    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.


  8. I started using Git recently and that is working really well for me too.


  9. +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.


  10. 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).


  11. Hey Mike, I’ll check out cat, thanks — it looks easier than merge if you only need to restore a single file. :)



  12. Max

    I was happy to find this today - thx! However, I think the syntax you want is -r73:68, not -r:73:68.



  13. Sandro

    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.



  14. Boaz

    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.



  15. ash

    syntax error. change
    -r:73:68
    to
    -r 73:68


  16. thank you so much! You have saved me hours of reading.



  17. Vinayak

    Awesome…just what i needed… Thanks



  18. Amrac

    Merci beaucoup :)
    (Thanks!)


Leave a Reply



Bad Behavior has blocked 0 access attempts in the last 7 days.