This website is not maintained anymore. Please visit www.nerdgirl.dkinstead  
This page was last modified: July 27 2010 13:22:12   
Too Cool for Internet Explorer

Subversion - commands

Deleting a file

Here I have a file I need to delete...

ls -1
.svn
configuration.php
index.php
installation.php
installation.php.old
monitor_activity.php
webdav.php

svn delete installation.php.old
D   installation.php.old

svn commit -m "Delete obsolete file"
Deleting   apache/installation.php.old
Committed revision 2.

ls -1
.svn
configuration.php
index.php
installation.php
monitor_activity.php
webdav.php

svn delete immediatly removes a file from both the repository and the filesystem, but a directory is not removed until you issue the svn commit command.

List of changes

If you run svn status at the root of your working copy with no arguments, it will detect all file and tree changes you've made.

Add new files and directories

Add a directory and it's contents:

svn add my_dir

If svn complains and tells you that the directory is already under version control, it's because the directory you're trying to add contains a .svn directory. I experienced this once, because the new directory I added, was a copy I made of an existing directory. So I just needed to remove the .svn folders within the new directory.

Add a directory without it's contents:

svn add --non-recursive my_dir

Add a new file

svn add my_file.txt

Add everything new, recursively. Go to the root of the working copy and do...

svn add * --force

Any svn add command must be followed by a svn commit. You can of cause do multiple svn add commands before committing.

Making changes

Open the file and make your changes, then do a commit:

svn commit filename -m "This is why I did the change"

You can also make changes to multiple files and then do:

svn commit -m "Changes done on multiple files...bla, bla"

Make sure you are in the root of the project when committing multiple changes. If your are in a subdirectory, only changes done within that directory is committed.

Ignoring files and directories

Ignore every file ending with '.log' in the log dir.

svn propset svn:ignore "*.log" log

Ignore all files in the log dir and the statistics dir

svn propset svn:ignore "*" log
svn propset svn:ignore "*" statistics

Procedures

Quote from the subversion book:

For projects that have a large number of contributors, it's common for most people to have working copies of the trunk. Whenever someone needs to make a long-running change that is likely to disrupt the trunk, a standard procedure is to create a private branch and commit changes there until all the work is complete.

Subversion has no internal concept of a branch-only copies. When you copy a directory, the resulting directory is only a 'branch' because you attach that meaning to it. You may think of the directory differently, or treat it differently, but to Subversion it's just an ordinary directory that happens to have been created by copying.

For example, let's say that Joe is starting a coding project scheduled for one month. Mary and Peter are currently correcting small bugs in the trunk. To prevent Joes project from interfering with Marys and Peters work, a branch is created for Joe:

svn copy file:///usr/local/www/subversion/nerdgirl.dk/trunk \
file:///usr/local/www/subversion/nerdgirl.dk/branches/joes_branch \
-m "Creating a private branch for Joe from /nerdgirl.dk/trunk."

With an interval of 7 days, changes from the trunk (Mary and Peters bug fixes) should be merged into Joes branch. This will prevent major problems when the time comes to merge joes_branch with the trunk, since it already contains all the changes made to the trunk.

This is how to merge changes from the trunk to a working copy of the branch (you must be sitting in the parent directory of your working copy when doing this)

svn merge -r 343:344 file:///usr/local/www/subversion/nerdgirl.dk/trunk joes_branch
cd joes_branch/
svn commit -m "Ported r344 (spelling fixes) from trunk."

In the above example, all changes done between revision 343 and 344 in the trunk, is merged into the branch. It is omportant to make a note of which changes you have merged. Next time you want to do a merge, you'll know which revision is already merged. This way you can prevent conflicts which is bound to happen if you merge the same changes twice.

Backup

The svnadmin dump PATH_FROM_REP > PATH_TO_FILE command writes data into a single, portable, flat file format.
The svnlook youngest PATH_TO_REP command gets the youngest (most recent) revision number of the repository.

Example of a full repository dump and load:

svnlook youngest /path/to/myrepos/
26

svnadmin dump myrepos > dumpfile
* Dumped revision 0.
* Dumped revision 1.
* Dumped revision 2.
...
* Dumped revision 25.
* Dumped revision 26.


svnadmin load newrepos < dumpfile

Example of incremental dump and load:

svnadmin dump myrepos --revision 0:1000 > dumpfile1
svnadmin dump myrepos --revision 1001:2000 --incremental > dumpfile2
svnadmin dump myrepos --revision 2001:3000 --incremental > dumpfile3

svnadmin load newrepos < dumpfile1
svnadmin load newrepos < dumpfile2
svnadmin load newrepos < dumpfile3