Praveen's Blog

An Eternal Quest for Incremental Improvement

Undoing a wrong commit in Subversion

Assume that you have done an accidental commit of a wrong version into the svn repository and wondering how to revert that commit, this tip is for you.

Let us take a case where one has committed a revision 543 of a file something.cc to the trunk and he discovers that the commit is an invalid one and he wants to revert to the revision 542. For most of the novice svn users, the command is not quite obvious. One should use svn merge to achieve this.

$ svn merge -r 543:542 http://your-svn-server/your-repository/trunk
U something.cc

$ svn stat
M something.cc

$ svn diff
...
# Verify if the change is reverted
...

$ svn commit -m "Undoing the wrong commit in revision 543"
Sending        something.cc
Transmitting file data .
Committed revision 545.

Please note that you should use the svn URI in the svn merge instead of using your local path for that file. It also should be noted that the revision 543 would still live in the repository. You can't make it to disappear as svn is designed not to lose any data. But the trunk is free of the buggy commit. It is not possible to achieve this using any other way like updating to the required revision and trying to commit it.


Comments