Categories
Posts

Revert to a Previous Version in Subversion

Most of the time when I’m working with code that is checked out from Subversion it’s moving forward, version after version. There are times though where I need to revert back to a previous version (one reason you should have your code versioned in the first place). Subversion can do this, but it isn’t via the revert command, instead it’s done with merge.

Most of the time this means I can revert my working copy to rev 12345 with this command:

svn merge -r HEAD:12345 .

The merge command requires a directory parameter, the dot just means the current directory. This only reverts your working copy though, so don’t forget to commit after merge.

Reverting back to a previous version is one of those things that I do infrequently enough that I end up searching for how to do it each time. Perhaps writing about it will help me remember this a bit better. If nothing else I know where to look for a quick example now.

5 replies on “Revert to a Previous Version in Subversion”

A little correction to the command:

svn merge -cr -[rev] .

if you use -c switch, you should not use -r switch, because

given 12345 is a previous revision number,

svn merge -r HEAD:12345

is equal to use the following command:

svn merge -c -12345

Awesome! Thanks! This was really helpful. I was missing the pointer to the current directory (.). All other websites were pointing to the directory of the trunk.

Leave a Reply

Your email address will not be published. Required fields are marked *