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.

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.
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.
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.
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.
Good to know, I’ve run into this one too. But can these commands also be executed in Eclipse, without using the terminal?
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).
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.
I started using Git recently and that is working really well for me too.
+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.
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).
Hey Mike, I’ll check out cat, thanks — it looks easier than merge if you only need to restore a single file. :)
I was happy to find this today – thx! However, I think the syntax you want is -r73:68, not -r:73:68.
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.
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.
syntax error. change
-r:73:68
to
-r 73:68
thank you so much! You have saved me hours of reading.
Awesome…just what i needed… Thanks
Merci beaucoup :)
(Thanks!)
Gracias!!!!
Thank you!!!
[...] whilst looking for a way to do this I came across a solution, which involes a revision merge and commit; basically taking your changes back to a previous [...]
# revert back to revision in one line:
svn update -r 2689
Gr8 work, like it this way
Thanks for the post, but the comment by petke worked much better for me – I didn’t have to resolve any conflicts during the rollback.
Hi,
Thank you very much for the information.
Regards,
Alan Haggai Alavi.
Thanks — this saved me quite a bit of work. I had to revert a change between two specific revisions that were NOT trunk. This worked like a charm.
[...] Aral Balkan – How to revert (roll back) to a previous revision with Subversion (tags: svn revert rollback) [...]
Thank you very much :-)
As far as I remember, you could just copy from an old revision to the HEAD revision, using the Repo browser. Unfortunately this is not possible anymore using the newest versions :-(
It was a very simple but still meaningful way.
Thanks for putting this up. Comment #20 above by petke works very well, too. I suppose that’s the way the developers intended for roll-backs, although I agree that “revert” seems more befitting than “update”…
[...] I use this method on most my projects (private and freelance), e.g. I’m using it to synchronize my theme right here on satf. This is awesome because I tend to break stuff and it’s comforting to know that salvation is only one revert away. [...]
Actually, petke’s way (using “svn up”) is *not* the same as using “svn merge”, and I don’t think it’s the way the developers intended for roll-backs. If you make changes after an “svn up” to a previous revision and try to commit them, Subversion won’t let you because your files are “out of date”.
Thank you for sharing this tip :)
Thanks !
If your working copy is on a network (it’s possible), you have to do like this :
2. svn merge -r73:68 http://my.repository.com/my/project/trunk \\my.network.name\my\project\
3. svn commit -m “Reverted to revision 68.” \\my.network.name\my\project\
Wait… can’t you just do “svn update -r “. That’s always worked for me…
Hello
The command: svn merge -r:73:68… throws a “syntax error in revision argument ‘:73:68′ ”
The first colon is a problem. svn merge -r 73:68… works fine.
The command is svn merge -r 73:68 and not svn merge -r:73:68 as you have mentioned. There is no colon after -r and there should be a space instead.
svn merge –dry-run -r:73:68 http://my.repository.com/my/project/trunk
should be
svn merge –dry-run -r 73:68 http://my.repository.com/my/project/trunk
Thanks for your very clear step-by-step explanation!
Thanks mate.
Thanks! This is just what I need. Anyway I use -rXX:YY not -r:XX:YY
Thank you!! That was real useful! :)
I just found your post after searching for an easy way to revert to previous rev on SVN. Found the post useful, and it helped me greatly. Thank you.
Just one thing I noticed in our version of subversion (1.1.4-2 .. very old) is that the command works best like this:
svn merge -r 73:68 http://my.repository.com/my/project/trunk
Thanks for the article Aral. I wasn’t able to get the revision flag working as you have instructed however. I think the initial semicolon following -r may be incorrect syntax.
*Instead of:*
svn merge –dry-run -r:73:68 \ http://my.repository.com/my/project/trunk
*Try this:*
svn merge –dry-run -r73:68 \
http://my.repository.com/my/project/trunk
Hi Aral,
Great article – short, explaining, useful! Exactly what I was looking for.
Thanks for that, and keep up the good work :)
Cheers,
Konstantin
Thanks for sharing. This was driving me nuts trying to figure out how to get going.
Thanks, quick and handy.
Very useful. The svn merge command is probably the most powerful in subversion. Love it.
Just to make a note on ‘petke’ comment. I just want to make sure people reading this dont think you are actually correct. The way explained on this tutorial is 100% the right way to do it. Petke way is just an update to a particular version. It is not a true revert, is just updates your local copy and does not affect the repository.
It is mainly use to viewing or grabbing past changes. I mainly use it for reverting one file at a time, as it is faster.
svn update -r 4 (on file)
-copy contents of r 4 of file
svn update (repository version, lets say 10)
-paste contents of r4 to latests
svn commit -m ‘revert to r4′
now you would be at r 11.
It’s important to emphasize that any new changes you’ve made that have not committed will be lost when you merge your old revision in with your working copy.
also, the syntax is -rN:N instead of -r:N:N (svn 1.6.5)
Please could you update the correct commands.
svn merge –dry-run -r73:68 http://my.repository.com/my/project/trunk
svn merge -r73:68 http://my.repository.com/my/project/trunk
try this:
svn up -r[insert revision #] [insert filepath]
thanks. it helped. for me though its not
-r:73:68 but
-r 73:68
@pan69
Cornerstone imo is the best Mac subversion GUI. You can do anything with it other than merging, but I prefer to do that kind of thing via cmd line anyway. It is most useful for visualizing changes, conflicts, viewing logs, etc. I like it a lot better than Versions and it is continually getting development updates especially now that it has a proper team working on it.
Thanks for the instructions!
The syntax is different for svn 1.x though. In particular:
svn merge -r 73:68 http://my.repository.com/my/project/trunk
Dude, your site keeps saying my comment looks like “spam”.
Thanks Aral, very useful. Unbelieveably it’s only after five years of using Subversion that I’ve finally needed to revert to a previous reivsion. Hopefully that say something positive about my coding. Just to note that the above did work, although I had to remove the first semicolon from the revision argument:
svn merge -r73:68 http://my.repository.com/my/project/trunk
what’s wrong with…
svn update -r 73
…?
svn merge -c -NUM .
(svn 1.6 and onwards)