tags:

views:

371

answers:

5
+3  Q: 

SVN reverse merge?

My SVN repository was perfect at revision 497. I performed several bad commits, so that now it is at revision HEAD. I see that to rollback you should use a command like this:

svn merge -r HEAD:497 .

while in the working directory (and the working directory is at the HEAD revision). But is that the right command? Or do I use HEAD:498? or 496? I already ran that command and the current revision doesn't appear to be the same as 497, because when I update -r 497 (or when I have a 497 working copy and I update -r HEAD), a lot of file updates occur.

Do I have some sort of fencepost problem, where HEAD:497 actually reverts to 496, or something? Or is it that when I update, SVN goes back through each revision, despite the fact that the HEAD and 497 are identical?

Edit:

Just to clarify, as I said earlier when I update between 497 and my merged HEAD, I see a lot of file changes take place. I thought that if 497 and HEAD were identical, it would detect that, and no file changes would occur; it would simply say "Updated to revision 497." So is my command wrong, or is this thinking wrong? (and if so, why?)

+1  A: 

If you want to undo r123, you need to svn merge -r 123:122 .

This means you need to run

svn merge -r HEAD:497 .

To verify run:

svn diff -r 497
Sander Rijken
Thanks for fixing your error :)
Ricket
+1  A: 

Does this help?

http://svnbook.red-bean.com/en/1.1/ch04s04.html#svn-ch-4-sect-4.2

sakabako
A: 

To back out of an undesired change (perhaps you committed other files that had debugging statements in them, along with something you really did want to commit), say the bad change was -r10:

svn update
svn merge -r10:9 <URL of your repository base> .

Now you can bring back just the file you did want to commit:

svn update
svn update -r10
svn commit <just that one file>   # this is the command you meant to type from the beginning
Ether
+3  A: 

If your repo was in pristine condition at revision 497, then I think you're correct, you need to do a:

svn merge -r HEAD:497 .

That merge command will only change files in your working copy, so remember to also commit the changes to update HEAD in the repo.

After you do the merge, followed by the commit, try comparing revision 497 to HEAD and they should be identical.

Dave Paroulek
What is the easiest way to compare 497 and HEAD? This is a huge repository and the merge command alone takes 20-30 minutes; is there a command that can run server-side and just tell me if they are identical, or do I have to get the two revisions into two separate folders and do a diff myself?
Ricket
I usually use the eclipse subclipse do do a compare, and pretty sure it is running a varations of the `svn diff` command behind the scenes and, like you said, even with a small-medium sized repo, it can take a long time to do a compare. I usually glance thru the log to get a feel as to whether a revert and/or a merge worked the way I expected.Here's a link to more info on the svn diff: http://svnbook.red-bean.com/en/1.4/svn-book.html#svn.tour.history.diff.wcrepos
Dave Paroulek
Okay, I successfully reverted. Since the first time didn't work, this time I did HEAD:496 and then 496:497, then committed. Interesting, after the commit it still thought I was at r507 so I had to svn update to become r508 (which it just committed); the update did nothing of course. I then did use svn diff, specifying two URLs, and it apparently did a server-side diff because it was quite quick to return a blank screen. A test diff with a different revision confirmed that blank is good; identical revisions at last. :)
Ricket
Did you commit a specific file? Commit updates only revision of the files it changes, update gets you back with all files at a single revision.
Sander Rijken
A: 

If you want a quick and reliable way to rollback to a particular revision, then just check out the older revision of the repository.

Run svn info to remind yourself what your repository URL is, then create a new folder and checkout the revision you want:

cd <your new folder>
svn checkout <URL> -r 497 .

Then you can diff that folder against your existing folder, and you can commit that entire revision back into the repository from there if you need to.

Dan J