Page 153 -
P. 153
Update the working copy of the code
When a programmer needs to modify the code for a project, the first thing to do is to bring
his working copy up to date so that it reflects all the changes that are in the latest revision.
If he does not yet have a working copy, he can check one out of the repository with the
svn checkout command.
The programmer supplies the URL to the repository and, optionally, a path to check it out
into. If no path is specified, Subversion makes a new subdirectory in the current directory
and checks it out there. The following action will check out the “trunk” branch from the
example above:
$ svn checkout svn://servername/hello-world/trunk hello-world --username andrew
A hello-world/trunk
A hello-world/trunk/hello-world.c
A hello-world/trunk/hello-world.h
A hello-world/branches
A hello-world/tags
Checked out revision 1.
Since the username andrew was given during the checkout, the working copy will remem-
ber that username. Before any changes are committed to the repository, it will ask the
user for a password. To avoid this, the --password flag can be used to specify the password.
(It is important for the URL to contain the trunk folder—otherwise, Subversion will grab a
copy of every branch and tag in the repository, which could be an enormous amount of
data.) The third parameter passed to the svn command is the checkout folder—in this case,
the user specified hello-world in order to check out the contents of the trunk into a folder
called hello-world. Without this parameter, Subversion would instead check out the work-
ing copy into a folder called trunk.
The svn update command brings the working copy up-to-date. If someone has committed
the file hello-world.c since it was checked out and that file has not been altered in the
working copy, the following command will update it in the working copy:
$ svn update hello-world
U hello-world/trunk/hello-world.c
Updated to revision 2.
The svn update command can also be called from anywhere inside the working copy. In
that case, the path should be omitted from the command line:
$ cd hello-world/trunk
$ svn update
U hello-world.c
Updated to revision 2.
The letter next to hello-world.c is a code to indicate what action Subversion performed for
that file:
• A for a file that was added to the working copy
• U for a file that was updated in the working copy
DESIGN AND PROGRAMMING 145