Ever made that commit that messed up your repository and spent some time wondering how to undo, or revert a bad commit? In subversion you really can’t go back a revision, but you can merge your copy with the previous repository version and then commit the changes to correct your mistakes:
svn merge -r [current_version]:[previous_version] [repository_url]
svn commit -m “Reverting previous commit and going back to revision [previous_version].”
This is a life saver
UPDATE: Julian found a ‘typo’ on this post. Corrected. Thanks Julian!
UPDATE 2: I found a horrible typo on one of my comments. Phew…
Anyway, I am glad that this post is helping people to resolve their problems
Surely that second command should be “svn ci -m…”, as in checkin not checkout?
Anyway, nice tip, worked for me
Yes, commit. Thanks for having found the little mistake
Thank you thank you.
Note that recent versions of subversion have added the -c shortcut to select one particular revision number. So the command can now be shortened to:
svn merge -c -[bad_revision] [repository_url]
Note the ‘-’ vefore the revision number. It’s important.
-c [y] is equivalent to -r [x]:[y]
-c -[y] is equivalent to -r [y]:[x]
We want the second variant here.
Extra tips:
(i) Note that reverting this way won’t restore your local copies to what they were before. It’ll revert them to [previous_version]. So you may want to make copies of your changed files before you do the revert.
(ii) Don’t forget the handy ‘–dry-run’ flag if you are not sure you have got the command right. svn will report what the command is going to do, but it won’t actually make any changes to your repo or local copy.
(iii) If, when you try to revert, you get a warning such as:
Skipped missing target: ‘…somepath…’
it means you have may have missed the branch part off your URL. You probably need to add a “/trunk” or a “/branches/yourbranchname”. For example:
http://mysvnrepo.net/repo/foo/trunk
instead of
http://mysvnrepo.net/repo/foo
ty =))
Thanks for the post. Just deleted everything by mistake and committed ;(
Your post saved me!
this is better:
http://blog.johang.se/2009/03/revert-commit-in-subversion.html
good stuff, just needed a quick manual on undoing commits…
nice one! it helped me really a lot.
Simply thanks. It saves me!
“svn merge -c -REV” is good but the above command allows for reverting multiple revisions at once. Both have their place and time to use.
Thank you, Lucas!
Great, thanks.
To explain sarniak’s short “this is better” message he suggests that you use the -c argument to only have to present one revision number and to do it with a ‘-’ sign in front of the version to reverse whatever changes were made with it.
Lastly, he would suggest just pointing to the local checkout with ‘.’ to avoid having to put in the whole URL.
You *can* do this automatically in Tortoise SVN.
Goto root directory, right-click>Tortoise>show log, select the revision, then right-click>revert.
NB:You can’t get to this option by right-clicking a file>show log. MUST be done from the root of the project.
Hey Robin,
Thanks for the tip on using tortoise SVN, I use svn only on linux using the default command line client, so your tip is very welcome
Thank you. This is saving me a lot of hours and frustration!
@ Robin Spark: Thanks for this Tortoise SVN tip!!!
Thanks, saved my life!
Thanks ! you save my Day!!
thanks, this was really useful in emergency!!
Thanks – took me a moment to work out how to do the same in TortoiseSVN, but it worked
Thank you
Great article! Helps a lot ! My life is also saved! ^^