How do I return to an older version of our code in Subversion?
Basically you need to "merge backwards" - apply a diff between the current and previous version to the current version (so you end up with a working copy looking like the old version) and then commit again. So for example to go from revision 150 (current) back to revision 140:
svn update
svn merge -r 150:140 .
svn commit -m "Rolled back to r140"
The Subversion Red Book has a good section about this.
Just use this line
svn update -r yourOldRevesion
You can know your current revision by using:
svn info
You can only commit new changes at the head of the subversion history.
The reason you can't do anything directly with the good copy you have on your PC, is that its .svn
folders know that it is code from the past, so requires an update before any commit.
Find the good revision number and revert
Find the revision number of the old copy you want.
Get your current revision with:
svn info --show-item revision # or svn log
Or to check older versions of your project, use:
svn update -r <earlier_revision_number>
until you find the right revision number.
Note down the good revision number (assuming
123
for examples below).Update to the latest revision:
svn update
Undo all the changes between the revision you want and the latest version:
svn merge -r HEAD:123 . svn commit -m "Reverted to revision 123"
(the same as Jon Skeet's answer above.)
If you can't find the revision number
If you can't find the old copy, and you just want to commit the files currently on your PC:
Make a copy of your good version (but without any
.svn
folders):cd .. rsync -ai --exclude=.svn project/ project-good/
Now make sure you have the latest version:
cd project svn update # or make a fresh checkout svn checkout <url>
Copy your good version over the top of the working copy.
This command will copy, and also delete any files from the working tree that aren't in your good copy, but it won't affect the existing
.svn
folders.cd .. rsync -ai --exclude=.svn --delete project-good/ project/
If you don't have rsync, you can use
cp -a
but you will also need to delete any unwanted files manually.You should be able to commit what you have now.
cd project svn commit -m "Reverted to good copy"