Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I rollback my subversion repository to an earlier version

We've just spent two weeks working down the wrong path on a problem (with all the commits to our SVN repository that go with that). We've now come up with the right solution (which needs our code base to go back to what it was two weeks ago). We should have branched two weeks ago, but that is irrelevant now.

Clearly, I can make a second checkout of the project and then copy that over the current version of the repository and check that in.

Is there a cleaner way to do this without a second checkout?

like image 317
BIBD Avatar asked Jul 08 '13 19:07

BIBD


3 Answers

There are many ways to do what you want. The simplest would be to check out a new copy of the codebase to a dev machine, specifying the revision for the commit made just before you went down the wrong development path. Then, simply check that code back in as the latest revision. Not only do you effectively "revert" the codebase to that revision, if you find out that some element of your wrong solution was useful after all, you still have easy access to those elements.

Also, as was said, you can branch the codebase at any time, at any revision. Simply cut a branch of the revision before you began your work, and continue along your new dev path. Keep in mind that merging this branch back into the trunk could be problematic; you'd want the end result of development in the branch to replace the codebase of the trunk wholesale. That's possible but it can get messy.

like image 163
KeithS Avatar answered Oct 11 '22 18:10

KeithS


There are a few ways of handling this:

Revert your changes:

 $ svn merge -r$rev2:$rev1 .

This is assuming that $rev2 > $rev1. This will back out the changes between these two revisions. If you're backing out a single revision, you can use this:

 $ svn merge -c -$rev .

That is, the revision should be a negative number. This will back out just that one revision.

Recreate the Branch

If this work was not done on trunk, but on a branch, and you pretty much want to toss out that branch, you can simply recreate the branch, and even delete the old bad one. Branches (and tags) can be created from any point in time:

$ svn cp -r$rev $REPO/branches/$bad_branch/$proj $REPO/branches/$new_branch
$ svn delete $REPO/branches/$bad_branch
like image 39
David W. Avatar answered Oct 11 '22 20:10

David W.


The solution provided by Mike works for me.

In a separate branch

$ svn merge -r 303:302 http://svn.example.com/repos/calc/trunk

(this undoes the change between 302 and 303).

Then you can commit the changes in your branch, test and then merge back to the trunk as normal.

like image 28
BIBD Avatar answered Oct 11 '22 19:10

BIBD