Tuesday, May 06, 2008

Rollback with svn

Trickier than it may seem, but simpler than expected. This is how you revert/rollback to an earlier svn version and cancel/undo all the stupid things you have done. Example:
Assume: $STUPID_VERSION is the version that messed things up, $LOCALMODIFIEDDIR the place where things change (must be svn-controlled of course, but can be a subdir of the project, if this is desired)

$ cd $LOCALMODIFIEDDIR
$ svn merge -c -$STUPID_VERSION .

Note the dot at the end '.'; Found here, at this good guy's blog.
.. oh, and NEVER NEVER NEVER copy entire svn-controlled directories!!! the ".svn" hidden dirs are chaotic evil.

Now, it's quite probable that a future commit will result in failure because of "file already exists"... Therefore, make a local copy of the affected $LOCALMODIFIEDDIR somewhere without svn (let it be $BACKUPDIR), DELETE the ".svn" inside, and:

$ svn delete --force $LOCALMODIFIEDDIR
$ svn commit -m "deleted the dir"
$ cp -r $BACKUPDIR $NEWDDIR
$ svn add $NEWDIR
$ svn commit -m "stupid error fixed "

So simple... :-(

No comments: