52

I just did an svn merge to merge changes from the trunk to a branch:

$ svn merge -r328:HEAD file:///home/user/svn/repos/proj/trunk .
--- Merging r388 through r500 into '.':
A    foo
A    bar
   C baz1
   C baz2
U    duh
[...]

But there were too many conflicts, so I'd like to undo that.

One way to do that is to commit and then merge back. But I can't commit because of the conflicts. What's the best way to undo in that case?

4 Answers 4

124

Revert recursively from the top of your working copy:

svn revert -R .

You will need to manually delete the files that were added. As in after reverting, the files added will remain on disk but they will be in a non-tracked state ("? foo")

2
  • 3
    This command will also revert any local modifications that existed before you did the merge though correct?
    – NeilMonday
    Mar 12, 2012 at 17:32
  • 4
    @NeilMonday true, but then you shouldn't merge into a working copy with local, non-merge-related changes anyway.
    – richq
    Mar 25, 2012 at 14:43
7

As long as you haven't commited, you can always do a revert to undo all your changes.

3
  • Hmm, just svn revert . didn't do anything.
    – Frank
    Dec 13, 2009 at 16:26
  • OK, then you should resolve everything first, then do the revert.
    – tangens
    Dec 13, 2009 at 16:28
  • 6
    ...and like @rq said, don't forget the -R flag to do the revert recursively.
    – tangens
    Dec 13, 2009 at 16:30
2

I faced the same situation, also I had some other changes which I didn't wanted to lose. So, instead of full recursive revert just svn revert for the conflicted items was good for me

svn revert baz1 baz2
-11

Just do svn resolve on all conflicts anyway and commit:

$ svn resolved baz1
$ svn resolved baz2
$ svn ci -m "oops. bad merge. will revert."
Transmitting file data ......
Committed revision 501.

Then, officially undo it by merging back to where it was:

$ svn merge -r501:500
--- Reverse-merging r319 into '.':
[...]

That's it, the merge has been undone in the directory. Now commit that too:

$ svn ci -m "bad merge has been undone"
Transmitting file data ......
Committed revision 502.

The advantage over the svn revert -R . method is that the files that were added are all properly removed.

2
  • 4
    You don't really want to be puking conflict markers into your repository's permanent history, do you!? Yuck.
    – bendin
    Dec 13, 2009 at 20:04
  • @LakshmanPrasad If someone checks out/updates in between these two commits the conflict markers will end up in someone's working copy...
    – BartoszKP
    Dec 5, 2018 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.