28 Aug

Eclipse and Subversion: Reverting a bad commit

Command line
If you want to revert a bad commit using SVN you can use a svn command. The following command rolls back changes made in revision N, using a reverse merge:

svn merge -c -N

Note the minus character in front of N. This is equivalent to the following command:

svn merge -r N:N-1

Rolling back multiple changes (let’s say revisions LOW to HIGH, both inclusive) works the same way:

svn merge -r HIGH:LOW-1

When using Eclipse with the subclipse plugin, there is even a more comfortable way of reverting a bad commit. Let’s assume the HEAD revision of the current trunk is revision x. And we would like to roll back all changes committed in revision x-20. But at the same time we want to keep changes committed after revision x-20, namely from revision x-19 to revision x. The steps in subclipse are:

  • Right click on the project or file(s) you want to do the revert on, go to Team –> Show History
  • Search in the history for the revision you want to revert select it
  • Right click on the revision to revert and choose “Revert changes from Revision x-20″

The Subversive plugin does not provide a single button click to revert a bad commit. Using a reversed merge can undo the commit. You can find the “merge” in the team context-menu when right clicking on your file/project. When clicking on the “merge” context menu item, a dialog will open where you have to enter

  • the project svn url
  • revision (browse the revision you want to revert and the previous revision of that revision)
  • check reversed merge

So, the steps in subversive are:

  • Right click on the project or file(s) you want to do the revert on, go to Team –> Merge…
  • enter the project svn url
  • selecting the revision to revert (and the previous revision of that revision)
  • check reversed merge
  • click “OK”

To give a concrete example, let’s imagine that you want to revert the last commit of a specific file. Let’s say the revision it belongs to is 4929. The last change of this file refers to the revision number 4859. That means that there were many other commits between the last and the new change of this file. To perform a reversed merge (revert the last commit) you have to select the revision 4929 and 4859, check the Reversed merge checkbox and click “OK”. Be aware that this seems only to work, when the revision exactly contains the files you want to revert.


Leave a Reply

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

six − = 1

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code lang=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" extra="">