Question

I need some clarification about the behaviour of "svn switch". I'm using SVN version 1.6.5.

From reading the manual, my understanding of the behaviour is that local changes will be preserved. So I would expect a locally-added file to still exist in my working directory after svn switch.

However, my colleagues and I have seen several instances where new files get deleted by the switch. Unfortunately, we can't figure out how to reproduce this.

Is there some circumstance (either a feature or a known bug) under which svn switch deletes locally-added files?

Was it helpful?

Solution

I think it's a bad idea to switch, when you have uncommitted changes. First, commit your local changes to a branch with svn cp . <branch URL>, and then switch. There may be very tricky situations you can get into otherwise.

Imagine, that in a version you're switching to, the files you added locally already exist, and are completely different. Or, what if you added a whole directory of files, which can't be adequately merged with the files in the version you're switching to. Do you really want that one big conflict?

There's "S" state shown by svn status, meaning that different parts of your source tree have different versions. It happens exactly when SVN is confused with local changes during a switch. It just gets broken in a middle of switch, and then it's a pain in the neck to recover. Happened to me several times. That's why I always make sure, that my working copy has no local modifications before I run svn sw.

OTHER TIPS

It should not delete either locally added files or unversioned files. The edge cases are where a directory is moved or removed by the switch, but there should be a tree conflict in that case.

What I often do, if I think there may be tree conflicts, is to save a patch of my current changes. Then I know I can wipe out my working copy and start again if necessary, without losing my work.

svn diff > ../somewhere/safe/save.diff
# Break stuff
patch -p0 < ../somewhere/safe/save.diff

The behaviour of svn switch is very similar to svn update: If the target of the switch is a path in which some file is missing with respect to the working copy, those files will be deleted from the working copy.

Like Ivan said, you should commit your changes and then switch.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top