8

I mistakenly committed the wrong change to file, for a simplified example's sake let's call it foo.txt:

foo.txt, rev 300 (correct):

 E = mc^2

foo.txt, rev 301 (incorrect):

 E = mc^3

How do I re-commit rev 300 to the next commit? If I update foo.txt to rev 300, I get the right file but its status is correct & doesn't require being committed.

NOTE: It's only foo.txt that I want to revert. The other revisions in rev 301 are important and I need to keep them.

Jason S
  • 184,598
  • 164
  • 608
  • 970
  • 2
    possible duplicate of [Better way to revert to a previous SVN revision of a file?](http://stackoverflow.com/questions/345997/better-way-to-revert-to-a-previous-svn-revision-of-a-file) – Sander Rijken Sep 27 '10 at 20:40
  • That doesn't seem to work for me; either it's different or I'm doing something wrong. – Jason S Sep 27 '10 at 20:44
  • oh wait, I missed the "-" before the rev #. Yeah, it's a duplicate. – Jason S Sep 27 '10 at 20:47
  • 1
    the - sign means, reverse this revision. Otherwise you get a normal merge, so you try to apply the changes made in that revision (which is a no-op, as the changes have already happened) – Sander Rijken Sep 27 '10 at 20:54

3 Answers3

15
svn merge -r301:300 foo.txt
svn commit -m 'revert foo.txt to 300'
DigitalRoss
  • 143,651
  • 25
  • 248
  • 329
9

If you're using TortoiseSVN, this is surprisingly easy. Just view the log for that file, right click on revision 300 and select revert to this revision (this is a local operation). Then you can commit your local file as 302.

Optionally, if this occurred quite some time ago, you can select revert changes from this revision. That will revert only the changes that occurred with that check in (you'd perform this on 301).

JoshD
  • 12,490
  • 3
  • 42
  • 53
  • No, I tried that. It lets me revert to that revision but doesn't mark the file as dirty. – Jason S Sep 27 '10 at 20:46
  • Should work, take care of choosing "revert" not "update". Sometimes the overlay icons do not display the real state. On "commit" you should see the file as dirty in the list. – jdehaan Sep 27 '10 at 20:49
  • 1
    @Jason: Odd. Last time I had to revert a revision, I did precisely what JoshD said and it worked just fine. – David Thornley Sep 27 '10 at 20:49
  • "take care of choosing "revert" not "update"" -- that may have been it. I didn't see "revert" in the list of options. – Jason S Sep 27 '10 at 20:50
  • Yeah, I just tried it again. If I right click on a file, there's an "update to revision..." but no revert; Revert is missing. No idea why. – Jason S Sep 27 '10 at 20:51
  • GACK! I just reread this answer carefully, you go through the log for that file. sigh. thanks all... – Jason S Sep 27 '10 at 20:52
2
svn merge -c-301 .
svn commit -m "Reverting commit 301"
harald
  • 5,976
  • 1
  • 24
  • 41