svn: import in place

You have a set of files you want to import into an existing repository, but you want to keep them in place (say, a live website, where you want to create the repository without stopping the web services, or a working copy you want to keep working on).

These are the steps to import said files into an existing repository, keeping the files as a working copy (that is to say, import in place). They work because you can check out a (sub)directory from the existing repository directly into an existing directory.

Start by creating an empty directory in the repository, checking out this empty repository directory into the file system directory to be imported (making it now a working directory), then adding all of the files to the repository.

Steps:

  1. Create a URL in the the repository that matches the top level of the files to be imported

    % svn mkdir file:///path/to/svn-repository/some/path/top-level-dir -m "Make dir in the repository corresponding to top-level-dir"

  2. Change to the top level directory of the files to be imported

    % cd top-level-dir

  3. Check out the top level directory just created in the repository

    % svn checkout file:///path/to/svn-repository/some/path/top-level-dir .

    This will create a .svn directory (with supporting files!) in the top-level-dir, since you just checked out the top of that path from the repository.

  4. Add all the remaining files to the repository

    % svn add file1 file2 dir1 dir2 ...

  5. And commit!

    % svn commit -m "Initial import of top-level-dir"