Subversion Command Line Usage Notes

Overview

This page contains guidelines and examples of command line usage of Subversion. These notes are useful if you have setup an account as described in Creating a Subversion Repository under Linux.

Guidelines

Every directory in a working copy contains a subdirectory named .svn; you should never modify these subdirectories because they are maintained by the subversion client you used to check out the repository.

IMPORTANT: If you want to copy or move an item in a working copy, you should use svn copy or svn move instead of the copy and move commands provided by the operating system.

Subversion uses the svn:mime-type property to decide if a file is capable of contextual, line-based merging.

The svn:ignore property is attached to directories to tell the subversion client which files and subdirectories within the directory are not intended to be stored in the repository. The svn:ignore property contains a list of newline-delimited file patterns; any file or subdirectory matching one of the patterns will not be listed by the svn client as potential items for version control. The patterns found in the svn:ignore property apply only to the directory on which that property is set and not to any of its subdirectories. The following example shows how to omit all files in the current directory that end with .o.

svn propset svn:ignore . *.o

Importing a Project

I created a project stored at ~/public_html/test that I wish to place under version control. The project contains a single file called hi.php. I execute the following command to import the existing code into my repository.

cd ~/public_html
svn import -m "" test https://web5.ias.csusb.edu:8443/turner/repo/test 

Note that the above does not automatically turn ~/public_html/test into a working copy. To get a working copy, you should move ~/public_html/test to somewhere else as a backup and then checkout test. To move ~/public_html/test to ~/test, do the following.

mv ~/public_html/test ~/test

Checking Out a Project

After importing the initial project into the repository and moving the original project to another location, do the following to get a working copy of test in your web directory.

cd ~/public_html
svn co https://web5.ias.csusb.edu:8443/turner/repo/test 

Committing a Project

I modified hi.php. To merge this change into the repository, I executed the following command.

cd ~/public_html/test
svn commit -m ""

Updating a Project

To test the update feature of svn, I checked out another working copy of test in a temp directory. Then I modified test.php in the new working copy and committed this. To see the change, I updated the working copy in ~/public_html/test. The following command executes an update.

svn update

Automatic Merging

If two or more users try to commit changes to the same character-based file, Subversion will quietly merge the two changes if there is no ambiguity. To see how this works, modify two different lines in hi.php in two different working copies and then try committing the changes. The second commit will fail saying that hi.php is probably out of date. Perform an update and then inspect hi.php to see that Subversion has merged the changes correctly. Now, perform a commit to write the changes into the repository.

Resolving Conflicts

To see how conflict resolution works, I modified the same line in test.php in the two working copies and then tried committing both. When you try the second commit, it fails saying that test.php is probably out of date. You need to first perform an update in order to bring this file up to date. However, running update produces the following line within the output.

C  test.php

The letter C means that there is a conflict in test.php. If you try to commit at this point, it will fail saying that conflicts exist. You need to edit test.php to manually resolve the conflicts. After doing this, tell Subversion that you have resolved the conflict by executing the resolve command on the file and then committing. (Note: you can use svn resolved test.php as an alternative to the next command.)

svn resolve --accept working test.php
svn commit -m ""

There are 2 other possible aurguments to --accept that are commonly used: mine-full and theirs-full. If you wanted to abort your changes to test.php and use the changes committed my the other user, then use the following:

svn resolve --accept theirs-full test.php
svn commit -m ""

If on the other hand you wanted to remove the changes committed by the other user and incorporate only your changes, then use the following:

svn resolve --accept mine-full test.php
svn commit -m ""

Creating a New File

I created a new file in the working directory called hi2.php. To add this to the repository, I run an add command followed by an update.

svn add hi2.php
svn commit -m ""

Locking Binary Files

Because Subversion can only merge character-based files, files in binary format must be managed using a lock-modify-unlock process. Binary files include image files, sound files, files stored in application specific formats (such as Word and Excel), and other file formats that are not character based.

To see how this works, add an image file to the repository through one working copy and update it into the other working copy. Then issue the lock command in one working copy and try to issue the same lock command in the other working copy; the second lock command will fail.

svn lock image.bmp

There are 2 ways to unlock a file that you locked. First, you can modify the file and then commit the changes. In this case, subversion removes the lock when you commit. Second, you can leave the file unchanged and simply issue the unlock command as follows.

svn unlock image.bmp