Subversion: How to revert to a previous revision

You’ve been there. You have been developing in your trunk for a while and at revision 127 you get the feeling you’ve done it all wrong! The production server is humming away at revision 123 and that’s where you want to start out again. But how can you start again from revision 123? Easy as this with Subversion

$ svn merge -rHEAD:123 .

This will see what changes you’ve made since r123 up until now (r127 in your case) and ‘undo’ them. Next you check in the code and you’ve go a sweet r128 that is exactly the same as r123. You can start over now!

  • Twitter
  • Digg
  • del.icio.us
  • DZone
  • Reddit
  • email

16 Responses to “Subversion: How to revert to a previous revision”

  1. Yanny says:

    Thank you so much for telling this! I really appreciate it, because I have looked everywhere on the internet and couln’t find it immediately, thanks!

  2. MJ says:

    You just saved my ass

  3. Joseph says:

    saved me hours of work =) thanks for the tip bro

  4. knocte says:

    FYI I’ve implemented a GUI method to do this operation in MonoDevelop:

    https://bugzilla.novell.com/show_bug.cgi?id=394434

    Regards.

  5. kaotisch says:

    Worked perfectly, thanks :)

  6. Cmyker says:

    Many thanks, very helpful post

  7. jason says:

    Tortoise svn does this well

  8. steve says:

    Excellent.

  9. Eric says:

    I was originally looking at the svn revert and checkout commands, but they really don’t have the right semantics. Thanks, merge is perfect!

  10. Michelle says:

    Hi there, I want to revert my working copy back to revision 3 which is my latest checked-in revision. I do the following:

    % svn merge -rHEAD:3 ./

    Now I would expect that there should be no difference between my (reverted) working copy and the latest revision in the repository (revision3). However it appears that the merge did not work, as:

    % svn status
    ? sites/all/modules/cvs_deploy
    M sites/all/modules/CVS/Entries.Log
    M sites/all/CVS/Entries
    ! sites/all/CVS/Entries.Log
    M sites/CVS/Entries
    ! sites/CVS/Entries.Log
    M misc/CVS/Entries
    ! misc/CVS/Entries.Log
    M CVS/Entries
    ! CVS/Entries.Log
    ! includes/CVS/Entries.Log
    ! modules/aggregator/CVS/Entries.Log
    M modules/color/CVS/Entries
    ! modules/color/CVS/Entries.Log
    ! modules/node/CVS/Entries.Log
    M modules/CVS/Entries
    ! modules/CVS/Entries.Log

    Perhaps I am doing something wrong or not understanding something.

    Please, any explanations or comments?

    Thank-you in advance,
    Michelle

  11. What Haveyou says:

    Thanks, but that didn’t work:

    svn merge -rHEAD:85008
    svn: Try ’svn help’ for more info
    svn: Merge source required

  12. damn fool says:

    You missed the trailing ‘.’!

  13. D Suave says:

    Thanks!

  14. Mads Kristensen says:

    Thanks a lot. I googled “subversion revert to revision” and found this post which solved my problem in five seconds :-)

  15. GeorgeP says:

    Another ass you’ve just saved is mine, thanks!

  16. slush says:

    Brilliant!

Leave a Reply