Subversion: Revert to Earlier Version

This is one of those annoying little things I have to do ever so often. There are two different commands to accomplish this task depending on the specific situation.

If you've made a lot of changes to a file and need to back all of those changes out, you can use the svn revert command. This command returns the file to the state it was in before any edits were made. In other words, once this command has been run, the file should be in the state it was in after your last commit.

Unfortunately, you may need to return a file to the state it was in before the last commit. The svn revert command can not revert a file to a previous version. In order to do that, you have to use the svn merge command. The Subversion Book has a nice description of how to undo committed changes. The most common method of backing out a change is svn merge -r N:M PATH where N is the revision number that has the change and M is the revision you want to fall back to. In the case, all changes made to PATH between versions M and N will be backed out. You can also use the svn merge -c -M PATH form to back out all the changes made between version M and the previous version. This has the effect of backing out a single commit and saves typing a few characters.

My Bookshelf

Reading Now

Other Stuff