tags:

views:

413

answers:

3

I made some changes and commited them (to version 2), and found out that they introduced new bugs to my program some minutes later. So I switched to some of the files to an older version to get some of the files back to version 1 on my local platform. Since then I have made a lot of changes I don't want to lose, and I have used commit (version 3) to get my local changes on the server.

The version I have locally is exactly what I want to be on the repository as head revision, even though some of the files are still officially on "version 1". I assume I should be using SVN merge in some way, but I'm not really sure how to do it. Any advice?

edit: When I use diff, it shows changes from the local version to the rep version. I could do update, but then I would have a non-working version locally again. So what I want is some kind of forced commit, that just says "this is the newest version, period".

edit2: When doing "commit", SVN reports that there are no changes. Thanks to Neil Butterworth for the question.

edit3: What I finally did, FYI: I should just have used Tim's suggestion, but I was dumb enough to do an update without really thinking about what I was doing. Of course, everything was then really messed up beyond repair. So what I finally did was to export the project to a new directory. That's obviously not the way you should do it, but I did not want to mess with this stuff any longer. In the end I had to get back to making actual progress on the actual project;-) I know that I can't do stuff like that when I'm working in a bigger team, but I'm not:)

+5  A: 

Brute force way:

  1. Make a copy of your local files.
  2. Delete all the .svn files in all the directories
  3. Check out the the HEAD version.
  4. Copy your local files onto the checked out HEAD.
  5. Check your local files back into the repository.

If you did it correctly, the SVN client should interpret the changed files as updates to the repository. This will however overwrite any changes other people have made that you may want to keep. If you want to keep those changes, do a diff on all the files first and incorporate all the recent changes, before making the final commit.

Reverse merge back to original revision:

  • For each changed file,
    1. Compare diff, note changes you want to keep, and change your local copy accordingly.
    2. Make a copy of your local files.
    3. Reverse merge HEAD back to desired original version.
    4. Paste your copy of the local files onto the merged local copy. (Delete .svn first)
    5. Commit

This is probably more manual unless you just revert everything back without checking for any changes.

Subversion, AFAIK, has no provision for an obliterate command yet, so all changes always happen to the local copy of the HEAD.

Reverting back is just a reverse merge, and all merges always happen on your local copy. In an ideal system, the merge will be tracked, but Subversion doesn't track merge information, so you might as well do method 1, and just make a comment in the commit log.

Some URLs to look up:

Tim
That would be plan B, if nothing else works. But would be quite some manual labour. I'd prefer doing it in a more clever way;-)
panschk
Yep, slightly annoying to perform, but it always works.
Simon Groenewolt
It's not really that manual. I've done it many times before. Assuming windows, Select all, copy, paste somewhere else. Search for all .svn, delete. Update to head. Copy old version, paste back. Commit.
Tim
From my point of view, this is not the correct solution. You should follow Suma's answer. Keep in mind that you can only commit a file if its local revision equals the HEAD revision. Therefore, you undo your changes by merging back the unwanted commit.
Andre
True, but that assumes that the number of files is small. Don't forget, he's got old files as well as changed files all mixed up. Figuring out what to revert will be very manual. Also, if other devs have since made changes that are good, reverting will wipe them out with no chance to fix conflicts.
Tim
If other developers have changed something, following your advise *will* overwrite the changes. I would recommend only to revert the commit(s) in question. Whatever solution he will follow, he'd better have a close look at the diffs before committing.
Andre
True. Sorry panschk, no easy way out.
Tim
Tim, I think you misunderstood what I meant. My suggestion is not to revert individual files, but to select a revision in the log and "revert changes from this revision". This will handle multiple files, and at the same time it will keep the changes made by other developers and any local changes.
Suma
Yes, that will work if you know which specific revision it is you want to revert.
Tim
+2  A: 

There are two possibilities here:

  • You effectively switched to a previous version of the repo, so you worked over version 1;
  • Or you checked out old versions of files over version 2, changed them and committed as a new version.

In any case, if you committed the changes successfully, that's what should be on the server.

If you're not sure, however, I'd recommend:

  • Keep a backup of your current files;
  • Check out a new copy of the repo;
  • If you see it's the same as your copy, then nothing else to do.
  • If not, overwrite all files in the new copy with your backup (except for hidden .svn folders!)
Seb
This actually makes more sense to me than the accepted answer. I've done this a few times myself.
WakeUpScreaming
+2  A: 

So I switched to some of the files to an older version to get some of the files back to version 1 on my local platform.

Instead of this you should have reverted the changes from the particular revision. You should be still able to do update and revert the changes from that revision after that.

Suma