Importing existing directory structure into new svn repository


For existing files, create and import directory structure into a new svn repository.

# create repository
cd path/to/repo
mkdir svnroot
svnadmin create path/to/repo/svnroot
# change to the webroot directory
# normally includes the webroot / website directory 
# such as cd ~/Sites/8080/website
cd path/to/webroot
# import the files into the repository
# note the last path segment includes the webroot directory name
svn import file:///...path/to/repo/webroot
# move the original directory away and checkout the files 
cd ..
mv webroot webroot-preimport
svn co file:///...path/to/repo/webroot
# and into the webroot for editing
cd webroot
# actual history for cut and paste:
% pwd
% ls -1
% mkdir svnroot
% ls -1
% svnadmin create /home/kitt/sites/8080/svnroot
% cd website
% svn import file:///home/kitt/sites/8080/svnroot/website
% cd ..
% mv website website-preimport
% svn co file:///home/kitt/sites/8080/svnroot/website
A    website/a
A    website/a/index.php
A    website/index.php
A    website/.htaccess
Checked out revision 1.
% ls

svn: import in place

Book page

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.


  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"