Cognitive Conga: a blog

Dancing the conceptual kerfuffle shuffle

Ratiocination, n. An instance of [reasoning]. Also: a conclusion arrived at by reasoning. Doubt the applicability of this at your peril leisure.

svn revert to revision

Sometimes I wish there was a '-r' argument to Subversion's svn revert command, so that I could revert my working copy back to a given revision. There isn't one, however, so how else can this be achieved?

The free Red Bean Subversion book gives some details here, but it's a bit vague on an important point. If you follow its instructions, and if your working copy contains uncommitted changes, then those uncommitted changes will be retained in the working copy. If that's what you want, then you're fine, but if not - in other words if you want to replace your working copy with a snapshot of the repository as it was at the point of the revision you want to "revert" to, you ought to:

  1. Change to the top directory within your working copy (assuming you want to roll back the whole of the working copy).
  2. run svn revert to revert your working copy's files to the state they were in when you last committed/checked out.
  3. run svn status -v to see which revision number your working copy now corresponds to (it's the highest revision number in the list that svn status -v produces).
  4. run svn merge -rXX:YY where XX is the number you obtained in the previous step and YY is the number of the revision you want to revert to.
  5. Done! The possible exception to this is that files in your working copy that didn't exist when revision YY was originally made, will still be there, because by default svn doesn't remove things. If you want to get rid of them, run a svn del [filename] on each of them.
  6. Well done! Now play with your working copy as though all those intermediate edits had never happened ;) . And when you're ready to commit your efforts, just use svn commit as usual!

Hopefully I won't be the only person this information has helped. :)

8 Responses to “svn revert to revision”

  1. Steve Turner says:

    “Hopefully I won’t be the only person this information has helped.”

    Well it just helped me! Found your page throuh Google and the merge to the previous rev was exactly what I needed.

    Thanks, Steve

  2. oli says:

    Worked a treat for me too – thanks!

  3. RAF says:

    Thanks, worked great! Ruben

  4. svnewb says:

    thanks! this saved me a lot of trouble!

  5. gdfd says:

    svn update -r 100 path updates the PATH to revision 100

  6. Tim says:

    If you use TortoiseSVN, the “Reverse Merge” option in the Merge dialog will do it.

  7. Ben says:

    what about: svn up -r 123

  8. maml says:

    @Ben – excellent dude. worked great for me.

Leave a Reply

You can use Markdown syntax and Markdown Extra syntax in this box.