« Home | 2010 Holiday Schedule » | Google Voice is not good with Indian accents. » | [How-to:] Merging Git Repositories » | US Bank ATM deposit + Double Hold = Major Headache... » | Gentoo: Recovering from installing a bad kernel » | Stock Market Crash Ahead? » | [Perl] Search and Replace Copyright in Source Code... » | [subversion] Using patches to manage temporary cod... » | We are now debt free... » | Screen Utility (and my .screenrc) »

[subversion]: How to revert a bad commit

Sooner or later, you are going to have to "undo" a commit.  Maybe your coworker checked in buggy code before heading out the door for their vacation, or maybe you didn't have enough coffee yet.  Whatever the reason, sooner or later you will have to deal with this issue.

Which leads us to the question: how do you undo or revert a bad commit?

If you are barely fluent with subversion, you might opt for the brute force method:

  1. checkout the previous version, rename the files in question;
  2. checkout the latest revision;
  3. copy the older modified (renamed) files on top of the newer ones;
  4. and finally check in the newer copy.

Tedious.  Especially if there are many files in different directories. 

There has to be a better way... 

Well, there is.  You can easily merge your copy with the previous version and then commit the changes back -- with one command.  Here's how.

First pick out the revisions you want to use.  List the revisions with the log command:

   1: svn log --limit 5

Next merge and then commit (replace the bracket text with your own):

   1: svn merge -r [current version]:[previous version] [repository url]
   2: svn commit -m "Reverting and going back to previous version."

Done.

Labels: