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:
- Change to the top directory within your working copy (assuming you want to roll back the whole of the working copy).
- run
svn revertto revert your working copy's files to the state they were in when you last committed/checked out. - run
svn status -vto see which revision number your working copy now corresponds to (it's the highest revision number in the list thatsvn status -vproduces). - run
svn merge -rXX:YYwhere XX is the number you obtained in the previous step and YY is the number of the revision you want to revert to. - 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. - 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 commitas usual!
Hopefully I won't be the only person this information has helped.
“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
Worked a treat for me too – thanks!
Thanks, worked great! Ruben
thanks! this saved me a lot of trouble!
svn update -r 100 path updates the PATH to revision 100
If you use TortoiseSVN, the “Reverse Merge” option in the Merge dialog will do it.
what about: svn up -r 123
@Ben – excellent dude. worked great for me.