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)
Thanks for the hint!
I think the argument -r:73:68 should be -r73:68 (without the colon). I got an error with the first version.
[...] good and detailed explanation of the revert process from aralbalkan. 53.734750 [...]
Extremely useful suggestion
Revision syntax of merge is wrong and would fail (at least it does on Subversion 1.6.5) with
svn: Syntax error in revision argument ':29:27'.Proper usage would be
svn merge -r 73:68 http://my.repository.com/my/project/trunk.if you are using subclipse, here’s another option: do team > show history on your project root. in the history view, select all revisions *after* the revision to which you wish to revert (e.g., if you want to revert to 260, select 261 and up). then, right-click and do “Revert Changes from Revision x to Revision y”. Optionally, verify the changes using “Team > Compare with”. Then commit.
colin
To rollback a specific file, just delete the one in your working copy and then run update to replace it with the one in the repo.
[...] new to svn, so this was NOT intuitive for me. Some helpful people on the interwebs (Anil and Aral Balkan) showed me that the right thing to do is “svn merge -r 4:1″ (the syntax is wrong on [...]
[...] Major mistake. I went looking for a reminder on the syntax of rolling back one’s changes, and found Aral Balkan’s explanation, which is terrific for its clearness. The syntax on my machine was slightly different than his [...]
For me (Mac OS X) this worked:
svn merge -r 73:68
and NOT
svn merge -r:73:68
Hi,
You made a mistake, it’s
svn merge –dry-run -r73:68 http://my.repository.com/my/project/trunk
svn merge -r73:68 http://my.repository.com/my/project/trunk
There is no : between -r and the revision number.
Regards
What if i want to revert the repository to a previous version but keep all my local modifications? I accidentally committed work that i wasn’t through working on locally, and i want to undo those commits.
Thanks Aral for such an easy-to-understand tutorial. You actually saved my day.. Otherwise I’d have had to explain hell lot of stuff to my supervisor on why the hell did I delete the whole branch instead of just the subtree in that branch which I was working upon.. Am so damn relieved now.. I just can’t thank you enough.
Regards
I a little trepidatious about doing this in general. I need to though. Sooooo, wouldn’t it be easier to just delete everything in the working copy and check out the old copy? But I guess, you are also reverting the repository version as well, on purpose?
The revert command confused me too. Your post has been very helpful, now I am able to undo changes that I have committed. Thanks!
I think instead of “-r:73:68″ it should be “-r 73:68″
Actually, it’s svn merge –dry-run -r 73:68 http://my.repository.com/my/project/trunk
not
svn merge –dry-run -r:73:68 http://my.repository.com/my/project/trunk
(notice the -r flag).
Such an old article, but still very usefull! I messed up our subversion website, and ‘revert’ did exactly what you described. Thanks to this article I used the correct merge (Which even removed files that were newly added.), and all is fine now. Thanks!
I got a syntax error with these instructions – it didn’t need the first : in between -r and 73
Didn’t notice that several people have already commented to that effect, whoops
Thanks very much, I was worried until you cleared this up :).
your first paragraph and a half sums up the problem completely! Thanks for posting. I’ve spent a while trying to figure this one out.
Thank you very much! That worked like a charm, explanation was good as well.
There is a small change that needs to be done:
The ‘:’ between r and 73 needs to be removed.
Steps:
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.”
Thanks SO much for posting this. Worked like a charm. This blog post has now saved my ass at work twice. :)
Thanks for useful information.
You have a little mistake: -r 73:68 instead of -r:73:68
In the version of the subversion client I have, there is no leading colon in the revision argument, so it would be:
svn merge –dry-run -r73:68 http://my.repository.com/my/project/trunk
Although the syntax wasnt exactly right (I think you’ve gort a extra colon there….) , the clearly set out simple steps was very comforting…and it worked.
There’s also a Revert in Subclipse for Eclipse. I don’t know if this is a Subclipse extension, or a native svn command, but it does what you’re describing here.
Thanks for the info. It was helpful. One note, you mistyped the revision arguments “-r:73:68″. It’s should be “-r 73:68″. Fixing it would make it easier to cut-and-past. Thanks.
Hey your command is wrong
its acutlaly
svn merge –dry-run -r 73:83 file
Note the space between -r and the revision numbers
Why not just copy the old version from the repo to your working copy. If you’re happy with what happens, commit. I’m pretty sure this actually won’t use any extra space.
Looks like you have slight syntax errors: -r:73:68 should probably be -r73:68 (without the first colon), as many people have already pointed out.
By the way, comments are somewhat hard to find, how about putting them where they usually are (below the article)?
Thank you for blog. This helped me.
Cool. Works like a charm!
Hi,
Great article as it just solved my problem however there is one small error (for me at least) in the commands.
Where you have “svn merge -r:73:68″ I have found that it errors, unless you remove the semi-colon behind -r and replace it with a space. So it I found it should be
svn merge -r 73:68 http://location
- Jonny (@DevJonny)
Really helpful, thank you!
Thanks for your great tutorial!
the -r parameter is not correct, however. it should be -r 73:68
You need a space instead of a colon. Maybe this is a result of an update to subversion.
svn merge –dry-run -r:73:68
Could you not just do…
$ svn switch http://my.repository.com/my/project/tags/previous_tag
Thanks! This is exactly I’ve been looking for!
Just simple and step-by-step.
you have a syntax error:
-r:73:68
should be
-r 73:68
Hi,
I think you made a typo.
It should be “svn merge -r 73:68″ with a space after “-r” instead of a “:”.
Kind regards,
Gijs
You need to delete the : between -r and the r number or you get an error. ie:
svn merge –dry-run -r 73:68 http://my.repository.com/my/project/trunk
Is there a mistake?
If I remove “:” after -r it works:
svn merge –dry-run -r 73:68 http://my.repository.com/my/project/trunk
Thanks, useful
“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.”
Nope. That doesn’t roll it back on the server; only locally. Just tried this an hour ago and pissed off some teammates who were waiting for the rollback.
-r73:68, not -r:73:68
It failed for me, I needed to drop the first colon after the -r
Oh, and no-one reads comments that are on the right-hand side of the page, that’s why several people have posted exactly the same fix!
Thanks for this, I have been trying to revert to a previous version in our repo but couldn’t do so. It was only displaying Skipped (version #)
I appreciate the plain English, but the syntax is not quite right, as has been mentioned by several other commenters. Can you correct your post, please?
Works perfectly! Thanks! :)
Just one fix : revision option has to be expressed as ‘-r73:68′ (without ‘:’ after ‘-r’, ‘-r:73:68′ generates a syntax error on my configuration (svn 1.4.2).
Thanks Aral,
Mate youve got an extra in your command by my svn …
svn merge -r 73:68
.. rather than ..
svn merge -r:73:68
Have fun,
Eugene.
Thanks, this was a life-saver after I completely messed up the trunk with an accidental bad commit.
Just a note though, I don’t know if this is version difference or something else (I see that this was written nearly 3 years ago), but my svn reported a syntax error in revision argument when written in the form -r:13:12. Instead, it was supposed to be written in the form -r13:12 (just removing an extra column after ‘r’).
If you just want to bring your local copy back to a past version just use:
svn up -r
Perfect. Exactly what I was looking for.
Cheers.
> you merge the changes from your current revision back to the revision you want to revert to.
I think a better way to say it is
you merge the previous revision into your working copy, and then commit those changes to the repository
So this has been here a few years, but still came in handy to get me out of serious jam. Thanks!
Thanks Aral,
This meets the user’s needs while maintaining full visibility but what about the actual repository itself? I have an svn mirror that got out of sync ( long story ) and literally need to prune off the last revision. Is there no simple solution other than svnadmin dump and rebuild?
Thanks,
… Robert Rath
[...] via Aral Balkan · How to revert (roll back) to a previous revision with Subversion. [...]
On subversion right click – there is revert to this revision option. What will happen when we click that ?
you saved my life today (more or less)
:D
Hi, there’s a tiny mistake in this page, the command ii should be svn merge -r 73:68 http://my.repository.com/my/project/trunk (ie no “:” between “-r” and “73:68″)
Thanks, just what I needed. I think there shouldn’t be a colon after the -r switch though – only between the two revision numbers:
-r 73:68
thank u so much dear friend
Thanks, this was exactly what I was looking for in an SVN project I’m working on. One small change. The -r:#:# format did not work for me. Instead, I had to do -r#:#. Note that the colon immediately following the r had to be removed.
The right command should be:
svn merge -r73:68
this helped me real quick! thanks.
Very helpful, the inly hangup I ran into was a command error where you wrote -r:73:68
I had to remove the first semi-colon for it to work and used -r73:68 or -rHEAD:68 to refer to the most recent revision.
Again, super helpful though, thanks.
Does it include the folder’s properties, like svn:ignore ?
There is a typo in the command line
(a colon after the ‘-r’ option)
WRONG:
svn merge –dry-run -r:73:68
CORRECT:
svn merge –dry-run -r 73:68
It seems that the options for r have to be given without the first colon.
That is
svn merge –dry-run -r 73:68 http://my.repository.com/my/project/trunk
Slight typo:
svn merge –dry-run -r 73:68 http://my.repository.com/my/project/trunk
then
svn merge -r 73:68 http://my.repository.com/my/project/trunk
So funny. I didn’t even notice that the content on the right hand side are the comments.
I naturally assumed that comments appear below the article and/or comment box.
Your instructions are somewhat wrong.
They should be:
-rxxx:yyy
Or to rollback from current head (working version) to an older one:
-rHEAD:yyy
or
-c -yyy
Where yyy is the previous version.
This really helped; as mentioned we don’t have to many places with precise info.
Thanks but the revision argument should be passed like -r73:68. You’ve got an extra colon in there.
good document.
None of the examples work – all yield:
“svn: Syntax error in revision argument ‘:72:71′”
I think the sintax changed to
svn merge -r73:68
without “:” between r and the first revision number.
Hey Aral,
Thanks for this, I spend lots of my time to search this. I was thinking that revert command is for this purpose but…:(… no . This blog is very very useful Thanks once again….. :)
– Yogesh
Git is very cool. Been using it for almost a year now.
svn rollbacks I do by checking out the previous version into a sandbox. Then I use ‘meld’ to visually compare and merge the 2.
Thanks
-r:73:68 should be -r73:68
(at least in my svn, version 1.6.12 (r955767))
s/-r:73:68/-r 73:68/
You should consider putting the comments in the more traditional location of just below the blog post. As you can see, a bunch of us assumed the sidebar had unrelated comments, and a bunch of us all corrected the same mistake.
That is quite helpful. But on your local file, you can do :
svn up -r revisionNumber TheFileYouWantToRevert
It works pretty good to. :-)
Thanks for posting this. Was very helpful.
Thanks, Very Nice steps
What if I want to revert to a previous version that was deleted and can’t merge?
that should be “svn merge -r73:86″
(you have an extra colon in your post)
Great !. Very good explanation. Thanks.
( A small correction in the following line
“svn merge –dry-run -r:73:68″
I think the “:” will not follow “-r” )
Thanks, saves me time figuring out how to do just this…
However, at least on my version of SVN, the “-r” command should look like “-r 73:68″ not “-r:73:68″
i think the correct command is
svn merge -r 73:68 http://my.repository.com/my/project/trunk
btw didn’t see the comments on the right, thought there were no comments :)
Thank you for the nice article, but I do believe there is a typo in it. It should be “-r 73:68″, not “-r:73:68″.
Thanks for this post, it’s indeed quite weird to use the merge for this, but it works fine!
Little syntax error: remove the ‘:’ after the -r, it should just be a space.
If I had not found this I would have ended up trying all kinds of functions in SVN before even considering to use merge in reverse.
Thank you for the precise and to the point blog post.
i think you have a syntax error.
the -r flag shouldn’t have a ‘:’ right after it.
i think it should be -r 73:68
Thanks for this hint :)
I know this post is a few years old, but there is still one thing to correct: There has to be a space after “-r”.
So it would be “svn merge -r 73:68…”
Error in your code:
svn merge –dry-run -r:73:68
should be
svn merge –dry-run -r73:68
If you get a:
svn: Syntax error in revision argument ‘:73:68′
… with the above -r:73:68 statements, then try -r 73:68 instead of -r:73:68
Another useful command in dealing with revisions is to be able to checkout a specific revision number (e.g.68):
svn co –username [username] –password [password] svn://my.repository.com/my/project/trunk@68
… or …
svn co -r 68 –username [username] –password [password] svn://my.repository.com/my/project/trunk
Thanks, made my day!
Great info, well written. Thanks!
While this is the first Google result if I want to revert something, it still has a minor error, so that this does not work.
The correct syntax for svn revisions is not -r:123:456 but -r 123:456
Else, thanks for the solution. It’s easier to Google this once a year when you need it than to memorize it :-)
Though this is extremely old, I found the command
svn update -r 68
to be more to my liking. Hope this helps someone!
SVN sucks GIT rules.
I was “forced” to use SVN for my current project and I’ve been wasting hours trying to make things like this work rather than working.