28

Using the Linux command line and Subversion, is it possible to take a directory and add version control to it?

Basically, I want to import the directory into a newly created repository, but also have the directory be a working copy without having to check it out.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
bkildow
  • 5,143
  • 4
  • 29
  • 37

2 Answers2

39

Let's say you've used svnadmin to create a repository at /svn/foo/mydirname, and you want to version control /home/user/mydirname (is that what you mean?).

Then do the following:

cd /home/user/mydirname
svn co file:///svn/foo/mydirname . #This only creates the ".svn" folder for version control
svn add ./*                        #Tell svn you want to version control all files in this dir
svn ci                             #Check the files in

Your directory is now version controlled!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
DaedalusFall
  • 8,335
  • 6
  • 30
  • 43
  • 1
    hmmm, its using c-style comments there for the highlighting. How annoying. – DaedalusFall Mar 24 '09 at 17:45
  • 2
    i think it needs a trailing dot, right? "svn co file:///svn/foo/mydirname ." – Brad Cupit Nov 17 '10 at 17:10
  • I wish I read this before I `rm -rf` ed my directory in order to checkout. – chustar Mar 21 '11 at 18:21
  • 2
    FWIW, if you are checking into a subdirectory (and not the root of the repo), and the directory doesn't exist, you can use the svn mkdir command to create the directory you are checking into- eg: svn mkdir --parents https://svn.foo.com/svn/projects/myProject/trunk – Tim Howland Aug 30 '11 at 14:01
  • Worked for me! Thanks! I deleted the old .svn folder, did a check out, then an add, then a commit from the TortoiseSVN gui and it worked. – toddmo Aug 11 '12 at 04:23
10

Yes, you can import an existing directory (with contents) into an SVN repository and use the current location as your version-controlled working copy. Go at it as follows:

Suppose your (un-versioned) project sources are in /home/user/projectx, and your repository is ready at file:///svnrepo

  1. First, create an empty directory somewhere outside of your project tree, say, /tmp/empty. Import that empty directory in your Subversion repository:

    cd /tmp/empty
    
    svn import . file:///svnrepo/projectx
    
  2. Go into your populated project directory. Now check out the repository location you created in step 1:

    cd /home/user/projectx
    
    svn checkout file:///svnrepo/projectx .
    

This will add the .svn files to your populated project directory, but it will not do anything else, so your existing files are safe.

  1. Next, add the directory with your files to the repository:

    svn add *
    
    svn commit -m 'initial commit'
    

Done.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pieter V
  • 26
  • 4
  • 3
    You need to add --force, otherwise svn will stop and complain about "svn: Failed to add file 'FILE': an unversioned file of the same name already exists – Artem Russakovskii Oct 23 '11 at 20:34
  • when following this procedure, I got the error "svn: E155015: [directory] is an existing item in conflict; please mark the conflict as resolved before adding a new item here" on each subdirectory added. I had to resolve each subdirectory before the "svn --force add * " would work, by using the command "svn resolved [directory]" – Craig Waddington Mar 01 '15 at 12:56