How to undo/rollback a Subversion commit? A fairly basic question, but every time I need the answer, I can't manage to remember it from the previous time I did it. Asking Google helps eventually, but the signal to noise ratio of the top hits is a bit disappointing. This time I couldn't resist the urge to throw my own bot snack in the intertubes.

Say you just made a commit (revision 123 for file apple.py), you discovered (after the fact) that it was just crap and you want the previous version (revision 122) back.

The common way to do it is with a merge of a reverse changeset (or something):

svn merge -r 123:122 apple.py

If your Subversion setup is recent enough (I successfully tried with version 1.5.1 for example) it is also possible to use the --change (-c in short) argument to specify the changeset:

svn merge -c -123 apple.py

The -c -ARG in this construct translates to -r ARG:ARG-1. Note the minus in front of the ARG: -c ARG translates to -r ARG-1:ARG, which is not what we need here.

Another possibility is using revision keywords:

svn merge -r COMMITTED:PREV apple.py

Note that this undoes the last commit, while the previous commands let you specify the changeset you want to undo.

One final note: this merging stuff only affects your working copy, you still have to commit the changes (after reviewing them of course) to the repository, e.g. as revision 124. The repository will still contain the crap version (revision 123), but this is generally preferred over trying to rewrite history in the repository.