Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I checkout an SVN repository, overwiting a non-versioned local directory?

Tags:

svn

Say my SVN repository looks like:

project/
    trunk/
        README
        foo/
            bar.sh

and I have a local, unversioned directory like so:

svn/
    project/
        trunk/
            README
            foo/
                hum.sh

if my cwd is svn and I svn checkout http://...project/ I get the following:

svn: Failed to add directory 'project/trunk': an unversioned directory of the same name already exists.

Fair enough. So: svn checkout --force http://...project/ does check out the repository, but leaves existing files as they are (and reports an E for existing).

Is it possible to checkout a repository, treating the repository as the 'preferred' version for any conflicting files? I.e. in the example above, I should end up with:

svn/
    project/
        trunk/
            README
            foo/
                bar.sh
                hum.sh

where trunk/README and trunk/foo/bar.sh are the versions from the repository, but trunk/foo/hum.sh is the local version. I'd expect a subsequent svn status to only report:

?    trunk/foo/hum.sh

UPDATE

Hint: I'm probably approaching this from the wrong 'direction' I'm betting sensible use of cp having checked out the repository 'to the side' would do what I'm after, but I can't quite get my head around it ...

like image 712
Bobby Jack Avatar asked Jan 17 '12 17:01

Bobby Jack


2 Answers

Yes, you're almost there with your svn checkout --force. To finish, do a svn revert -R on it. That'll throw away local modifications (but not delete new files).

edit: If you want to do it with cp, the -n, --no/clobber option should do it for you:

$ svn co https://…/FOO their-foo
$ cp -rn my-foo/* their-foo
$ cd their-foo; svn stat

should show only new files.

like image 134
derobert Avatar answered Oct 23 '22 12:10

derobert


You can use the svn revert -R command to recursively restore all files to the repository's version, where one exists. hum.sh would still be ? but all other files whether they were locally changed or were Existing will be restored to the repository version.

You can also use the svn update --accept theirs-full option which should also overwrite files marked as existing.

like image 41
Dan Avatar answered Oct 23 '22 11:10

Dan