1

I'm working in the SVN trunk of my project and I'm the only developer. Some days ago, I was asked to implement a new requirement, I began doing it in the trunk itself (bad choice, BTW):

r1154: Last revision with the old version (2.1.12).
r1155: I commited the new version here (3.0.0).

Later on, I was asked to fix some bugs in 2.x version, so I did a reverse merge and got the next revision in the same state as before:

r1156: Reverse merge to recover r1154 state as HEAD.
r1157: Some modifications.

Now my problem is I want to recover the modifications I did in r1155. Basically, I want to merge them with my current trunk state. How is it possible to achieve:

r1158: r1157 code merged with r1155 new features.
Aritz
  • 30,971
  • 16
  • 136
  • 217

2 Answers2

3

If the bug fixes you made in r1157 are independent of the new feature you originally added in r1155, you can try merging the changeset for the new feature back into trunk like this:

svn merge -c 1155 TRUNK_URL WORKING_COPY_PATH

This takes the differences between r1154 and r1155 and tries to apply them on top of r1157 (assuming your working copy is up to date).

Alternatively, you can try to "undo the undo" by reverse merging the changeset that removed the new feature:

svn merge -c -1156 TRUNK_URL WORKING_COPY_PATH

This takes the differences between r1156 and r1155 and tries to apply them on top of r1157 (assuming your working copy is up to date). The minus sign in -1156 is critical because it indicates that this is a reverse merge.

Note that this does not actually remove r1156. Nor are you "restoring" the repository to an earlier revision. r1156 was already committed, so it will stay in the repository forever, and HEAD will never point to r1156 again. You are simply applying the same changes as were made in that revision, but in reverse order, to your working copy. This is a critical point that you need to understand when doing merges in SVN.

Either way, if you touched the same bits of code in your bug fixes and in the new feature, you may get merge conflicts, which you will have to resolve manually. When you have resolved all conflicts, you now have to commit your changes to your working copy:

svn commit WORKING_COPY_PATH

Now HEAD will be at r1158 and both your bug fixes and your new feature will be there.

ThisSuitIsBlackNot
  • 23,492
  • 9
  • 63
  • 110
0

Reverse merge 1156 on top of 1157

Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
  • Thanks for your answer. Won't it remove every single change made from 1156 to 1157? As far as I understand a reverse merge is intended [to revert a change which has already been commited](http://stackoverflow.com/a/19533227/1199132). Also why choose 1156? Isn't make more sense to do it with 1155 which is the revision I want to recover code from? I would be grateful if you're able to elaborate the answer a bit more... – Aritz Aug 26 '14 at 17:20
  • @XtremeBiker `r1156` *is* a change that was already committed. With this approach, you would essentially be "undoing the undo;" alternatively, you could reapply the changes from `r1155`. Either way, be aware that if you touched the same pieces of code in the bug fixes and the new feature, you're likely to get merge conflicts, which you will have to resolve manually. – ThisSuitIsBlackNot Aug 26 '14 at 19:48
  • @ThisSuitIsBlackNot well, if I understand properly: I reverse merge r1157 to r1156 so I get the r1556 state again in my working copy. Then should I merge it with r1155 to apply the 3.x changes? And how to recover the bug fixes made in 1157 after that? What a mess :-S – Aritz Aug 26 '14 at 20:23
  • @XtremeBiker I don't think you're quite understanding what a merge does. It does *not* restore the repository to a previous state. A merge simply applies a changeset (in other words, a set of diffs) to your working copy. For example, you can apply the differences between `r1154` and `r1155` onto a working copy at `r1157` to "re-add" to your working copy the changes you originally made in `r1155`. You can then commit the changes to get `r1158`, which contains both the bug fixes and the new feature. See my answer for details. – ThisSuitIsBlackNot Aug 26 '14 at 20:54