1

So I'm looking around and not seeing my specific example. Hopefully this makes sense-

I'm looking for a way to delete changes that occurred in a file but in one commit and leave the changes that occurred after (all until HEAD).

For example

1st commit foo.js

var x = "hello";
console.log(x);

2nd commit foo.js

var x = "hello";
var y = "blah";
console.log(x);
console.log(y);

3rd commit foo.js

var x = "hello";
var y = "blah";
console.log(x);
console.log(y);
var z = "world";

4th commit (HEAD) foo.js

var x = "hello";
var y = "blah";
console.log(x);
console.log(y);
var z = "world";
console.log(x + " " + z);

Now I want to revert the 2nd commit so the file looks like

var x = "hello";
console.log(x);
var z = "world";
console.log(x + " " + z);

Got any tips for me? I'm looking to do this with a revert and not manually (removing the lines in the file and committing that)

I've tried (How do I revert an SVN commit?)

//svn merge -c -[R] .
svn merge -c -2 foo.js

and it got rid of all the changes after commit 2

Community
  • 1
  • 1
user2879041
  • 1,077
  • 1
  • 12
  • 25
  • 1
    There's no way to selectively *revert part of a file to a previous version without losing later changes*. How would SVN be able to determine what line of each revision you wanted to keep and which you wanted to discard? – Ken White Jan 30 '15 at 18:21
  • yeah I mean, that's why I prefaced with "Hopefully this makes sense" I kind of figured that it may not be possible, but I was wondering if there was some kind of trick/hack to do it – user2879041 Jan 30 '15 at 18:24
  • Do you know if it is possible in git? – user2879041 Jan 30 '15 at 18:26
  • No, because git can't read your mind either. There's no VCS that can read minds yet, although I hear it's in (far) future roadmaps. – Ken White Jan 30 '15 at 18:28
  • it's not really "mind reading" -- I'm not sure how you think this is some sort of impossible task, I'm sure that someone could figure this out – user2879041 Jan 30 '15 at 18:29
  • Good luck with that. If it's so easy, SVN is open-source. Write the code and contribute it to the project. Remember though, that SVN knows no information about your files other than the differences (deltas) from one version to the next, so it doesn't have the same capacity that a human does to sit and analyze what's on screen all at once. I look forward to the announcement of your joining the SVN project and the implementation of this feature to it. :-) – Ken White Jan 30 '15 at 18:31
  • Reverting the changes made in one revision is exactly the sort of thing a reverse merge in SVN is designed for. I see this was attempted, but it did not work for some reason. What was the output of that merge command? And what did the file look like after that command? – Ben Jan 30 '15 at 21:43
  • I don't think is a problem of "mind reading", but telling the tool what you want to do. `svn merge -r 2:1` should make it for your case. With the changes you describe, you won't get conflicts. – lrnzcig Feb 01 '15 at 09:17

1 Answers1

1
  1. You done all things correct
  2. For such "one-liners" you couldn't reverse merge without conflicts (and I can't see any sign of it in your message) , which must be resolved (probably by hand)
  3. If you use ancient SVN's version, it can give you additional headache
  4. If any case clean reverse merge can not affect any revisions, not included in merge range - reverse merge by desing is applying reversed patch from revisions in question only

Sample test in my repo with your data

>svn log
------------------------------------------------------------------------
r5 | Badger | 2015-02-01 12:03:39 +0500 (Вс, 01 фев 2015) | 1 line

Change 3
------------------------------------------------------------------------
r4 | Badger | 2015-02-01 12:03:00 +0500 (Вс, 01 фев 2015) | 1 line

Change 2
------------------------------------------------------------------------
r3 | Badger | 2015-02-01 12:02:02 +0500 (Вс, 01 фев 2015) | 1 line

Change 1
------------------------------------------------------------------------
r2 | Badger | 2015-02-01 12:01:22 +0500 (Вс, 01 фев 2015) | 1 line

Initial state
------------------------------------------------------------------------
r1 | Badger | 2015-02-01 12:00:01 +0500 (Вс, 01 фев 2015) | 1 line

Imported folder structure
------------------------------------------------------------------------

Your changes are in my r3, as you can see

>svn diff -c 3
Index: foo.js
===================================================================
--- foo.js      (revision 2)
+++ foo.js      (revision 3)
@@ -1,2 +1,4 @@
 var x = "hello";
+var y = "blah";
 console.log(x);
+console.log(y);

with HEAD-state

>svn cat foo.js
var x = "hello";
var y = "blah";
console.log(x);
console.log(y);
var z = "world";
console.log(x + " " + z);

and I can't reverse-merge it without conflicts (diff is context-aware) (my repo is single-file, thus I can use .)

>svn merge -c -3 .
--- Reverse-merging r3 into '.':
C    foo.js
--- Recording mergeinfo for reverse merge of r3 into '.':
 G   .
Conflict discovered in file 'foo.js'.
Select: (p) postpone, (df) show diff, (e) edit file, (m) merge,
        (mc) my side of conflict, (tc) their side of conflict,
        (s) show all options

and for such conflicts best strategy may be merging using any pre-configured GUI-tool

Conflict in TMerge

or editing file in-place (you know, which result you want to get)

Lazy Badger
  • 94,711
  • 9
  • 78
  • 110