Product SiteDocumentation Site

3.2.4. Working Copies

Now that the first revision of the project has been checked into the repository, it can be edited and worked on. To do this, a working copy needs to be created. This is done with the svn checkout command. For example:
$ svn checkout http://host.example.com/svn/repo/trunk
A	 trunk/README
A	 trunk/INSTALL
A	 trunk/src/main.c
A	 trunk/src/header.h
...
Checked out revision 8810.
$
A directory with a working copy of the project is now created on the local machine. It is also possible to specify where the local directory a project is checked out to with the following command:
$ svn checkout http://host.example.com/svn/repo/trunk my-working-copy
If the local directory specified does not exist, SVN will create it.

.svn subdirectory

Every directory in the working copy contains a subdirectory called .svn. Being an administrative directory, it will not usually appear with a list command. This is an important file and should not be deleted or changed. Subversion uses this directory to manage the working copy and tampering with it will cause errors and instability. If the directory is accidentally deleted the best way to fix it is to delete the entire containing directory (a normal system delete, not svn delete) and run svn update from a parent directory. The deleted directory will be recreated, including the missing or changed .svn directory. This can cause a loss of data.
Although the working copy is now ready to edit, keep in mind that whenever the file tree changes, these changes must be sent to the repository as well. This is done with a variety of commands.
svn add filename
Newly created files or directories, including the files they contain, are flagged to be added to the repository. The next commit will add them to the repository where they can be accessed and viewed by all.
svn delete filename
Files or directories, including the files they contain, are flagged to be deleted from the repository. The next commit will remove them. However, the deleted files can still be accessed in previous revisions through SVN.
svn copy filename1 filename2
Creates a new file, filename2, which is an exact copy of filename1. It then schedules filename2 for addition on the next commit. Note that svn copy does not create intermediate directories unless the --parents option is passed.
svn move filename1 filename2
This is the same as svn copy filename1 filename2 followed by svn delete filename1. A copy is made, and then filename1 is scheduled to be deleted on the next commit. Note that svn move does not create intermediate directories unless the --parents option is passed.
svn mkdir directory
This command both creates the specified directory and then schedules it to be added to the repository on the next commit.
Sometimes it is impractical to check out an entire working copy in order to do some simple changes. In these circumstances it is possible to perform svn mkdir, svn copy, svn move, and svn delete directly on the repository URL. The downside of using this is that with a working copy the changes can be checked before publishing them to ensure that is actually the way they were intended.