Subversion How To: Replace Trunk or HEAD with an Older Revision
January 22nd, 2007
Today I was pairing with another developer and we got a little ahead of ourselves and committed some rather drastic changes to the trunk/HEAD of our project. After a few more commits it became obvious that we were stepping on several other developer's toes, so we decided to revert trunk back to the revision just before we nuked the codebase.
Unfortunately, nobody knew how to do this, though it seemed like this should be a pretty common task, since just about everyone has wanted to erase the past for one reason or another. It didn't take much Google'ing to find the answer but the syntax was weird enough that I decided to show it here. Thanks Python Software Foundation's How-To for the tips.
The command:
svn merge -r NEW:OLD PATH
Example:
svn merge -r HEAD:101 http://subversion.example.com/project/trunk
Let's say you committed a real stinker at repository revision 20, and, since you've kept committing, the repository is now at revision 22. Here's how to revert HEAD back to the fresh-smelling revision 19. Here's the story:
[~/40withegg]# svn rm test/
D test/unit/asset_test.rb
D test/unit/core_filters_test.rb
D test/unit/tagging_test.rb
...
D test
Commit it!
[~/40withegg]# svn ci -m'JLM: deleting tests because I am crazy!'
Committed revision 20.
And, after some other craziness, we committed a few more things:
...
Committed revision 22.
Let's undo all of that. First, revert, just to make sure your working directory is clean:
[~/40withegg]# svn revert *
Next, perform the (horribly named for this purpose) svn merge, which will add the clean revision's code to your working directory as changes:
[~/40withegg]# svn merge -r HEAD:19 svn+ssh://joe@example.com/svn/trunk
A test
A test/unit
A test/unit/user_test.rb
...
A test/referenced_caching_test_helper.rb
Finally, commit the fix:
[~/40withegg]# svn ci -m"JLM: adding the tests back... man that was dumb."
Adding test
Adding test/actor.rb
Adding test/fixtures
...
Adding test/unit/user_test.rb
Transmitting file data .
Committed revision 23.
[~/40withegg]#
Hope that helps!
I'm
March 28th, 2007 at 01:14 PM
Thank you sir for taking the time to post this. It really saved the day. I owe you a beer.
December 12th, 2007 at 01:42 PM
Thanks a lot for that useful hint. Saved us a lot of time on or project.
April 11th, 2008 at 08:36 PM
thanks for this post. saved my life
May 7th, 2008 at 05:13 AM
Thank you so much!! It saved my day!! :D
May 27th, 2008 at 04:33 PM
Thank you!!!