Better way to revert to a previous SVN revision of a file?

sorry to use up some space on just a reiteration of the previously given answer - but this is something I always end up in trouble with.

Let's say I've updated the local files to the latest revision, which is 854. Then, I'd want to get an older revision - the version of the file from few revision earlier, say revision 851.

Copy would work:

svn copy -r 851 svn+ssh://<repository URL>/l3toks.dtx ./l3toks.dtx

.. however, I can't be bothered grepping for the repo URL :)

Update seemingly might work:

svn up -r 851 ./l3toks.dtx

... however, it also marks the local copy as "freshly checked out", or rather "same as online revision" (i.e. in Tortoise/RabbitVCS you get a green OK checkmark) - which means you cannot do svn ci -m "rolled back to r 851": simply because the local subversion executable won't notice any local changes, and won't be bothered to upload anything to the online repository.

And, as already answered, reverse merge works - but in this case, one shouldn't rely on shortcut syntax; but specifically state:

svn merge -r HEAD:851 l3toks.dtx
--- Reverse-merging r854 through r852 into 'l3toks.dtx':
U    l3toks.dtx

I must admit - I would never understand the sentence "Reverse-merging r854 through r852 into file" to mean "Just got r851 of your file, and overwritten whatever you had previously locally - and it is marked as different from latest online revision, so you can check it back in online as a new 'rollback' revision", but I guess (and hope :) ) that is what it does :)

After this, one can use svn diff for a quick make-sure if we got the right revision back locally; and also, the file will be marked with a red exclamation mark in Tortoise/RabbitVCS (that is, different from latest committed version), and so svn ci -m "rolled back to r 851" can run this time.

Also, note that if you, finally, change your mind after reverse merging (i.e. you anyways want to keep working on the latest, HEAD revision, here 854 - after you have rolled back to 851 locally, but haven't yet committed the rollback), you shouldn't use svn up, because it will simply say that it is already "At revision 854"; use instead svn revert --recursive . or similar...

Cheers!

Ref: How to Roll Back Changes using Subversion - Jacob Wright – Flex, AIR, PHP, etc.

EDIT: ... and apparently, the exactly same effect as svn merge -r HEAD:851 l3toks.dtx, can be achieved with:

svn export -r 851 l3toks.dtx
A    l3toks.dtx
Export complete.

Check out "undoing changes" section of the svn book


svn merge -r 854:853 l3toks.dtx

or

svn merge -c -854 l3toks.dtx

The two commands are equivalent.

Tags:

Svn