2008

2007

2006

2005

2004

Undo commit in subversion (svn)

▁ dec 11 2007

A quick google search will turn up a few blogposts and forumthreads on how to undo a commit in Subversion. This is the easy way to do it, and also serves as a note for myself.

Example: You were working on rev 1707 and you committed some donkeycode that you have to remove. The donkey revision is 1708. You want to roll back.

user@host% svn merge -r 1708:1707 .
U    media/shared/css/admin.css
D    media/shared/js/ajax.js
U    settings.py
U    urls.py

OK, so some files were “updated”, meaning that the code you wrote is taken out, and some files are deleted, which are files that you added in your revision. Now check that it only made the changes you wanted it to:

user@host% svn diff

If it all looks OK, go ahead and commit your “rollback.” It’ll get a new revision number, but that’s how SVN works.

Hope this helps someone.

← Previous: Battling Fibonacci  //  Next: The Current Pros and Cons List for SimpleDB

comments

Valere JEANTET, 11 months ago:

Great !!! Bravo !

Simon Brunning, 11 months ago:

It’s crucial that you only do this with an up to date, clean working copy, i.e. one without any changes. Run an ‘svn up’ and an ‘svn st’ first, and if anything shows up, sort that out before attempting a reversion. One alternative to this it to keep another working copy around specifically for doing reversions in. If you have a fair amount of reverting to do (as I did when I was team build-whip for a while) this is well worthwhile.

Leonardo, 11 months ago:

For some subcommands, like this one, there’s also the concept of changes. This is equivalent: svn merge -c -1708 . Note the negative argument. This reads ‘apply the change 1708 backwards’.

powered by