Subversion, or simply SVN, is an open source file repository manager. Its purpose is to store every version of every file that has been uploaded on the main server. That way developers can track all the changes, revert to older versions of a file, compare edits and deal with mess-ups. Each developer has access to a local copy of the repository and can manipulate with it using various commands. Let’s see some of the most common ones:

  • $ svn checkout URL PATH (checkout can be shortened to co): this command creates the local copy of a directory. The URL is the remote address where the contents of the directory are located. The PATH will be the local folder where the content will be copied. This command can contain multiple URLs which means for each of them SVN will create a new subfolder in the PATH directory. PATH is not required and defaults to the basename of the URL. This command is usually run once, at the beginning of a repository creation. Example:
$ svn co /my-projects/open4tech-projects/
  • $ svn commit -m "log message" (commit can be shortened to ci): this command is the only command that affects the central SVN repository. Unless something is committed, all changes related to it that are made on the local repository will be visible only in the local repository. The log message contains information about the changes and is very useful for easier tracking.
  • $ svn list URL: displays all the files in the given URL without copying them to the local repository.
  • $ svn add FILENAME: adds a file to the local working copy of the repository.
  • $ svn delete FILENAME: deletes a file from the local working copy.
  • $ svn diff FILENAME: shows the difference between the file in the local repository and the file in the central remote repository.
  • $ svn status PATH: shows the status of the local copy with a certain path. Example:
    $ svn status /my-projects/open4tech-projects/
    This will give a result looking like this
    M        /my-projects/open4tech-projects/Home.aspx
    A  +     /my-projects/open4tech-projects/archive.xml

    As you can see, the output contains some single character status codes. These codes belong to 8 categories and are displayed in 9 columns (in our case A and M are first column, + is fourth column). A column is left empty if no status from that category is present. Statuses from 6th and 9th columns require the use of the –show-updates (-u) option to appear. The possible status codes are:
    • First column (general file statuses):
      • A‘: scheduled for addition
      • D‘: scheduled for deletion
      • M‘: modified
      • R‘: file is replaced with another file with the same name
      • C‘: file contents are conflicting with these received from the central repository
      • X‘: file exists because of some externals definition
      • I‘: ignored
      • ?‘: not under version control
      • !‘: file is removed not by using SVN or during incomplete/faulty checkout or update
      • ~‘: item is replaced by different type of object (directory/file/link) from what it has been versioned as.
    • Second column (file properties statuses):
      • M‘: modified properties
      • C‘: file properties are conflicting with these received from the central repository
    • Third column (directory locking):
      • L‘: directory is locked
    • Fourth column (addition with history):
      • +‘: some history is scheduled with the commit
    • Fifth column (parent relations):
      • S‘: item has been switched relative to its parent
    • Sixth column (file locking):
      • K‘: file is locked in the local working copy
      • O‘: file is locked in another copy or by another user
      • T‘: file is locked with a lock “stolen” from another user
      • B‘: file has been locked but the lock is broken
    • Seventh column (tree conflicts):
      • C‘: there is a tree conflict involving this item
    • Eighth column (always empty)
    • Ninth column (update availability):
      • *‘: item has a newer version on the remote repository
  • $ svn log PATH: shows the log for the directory (list of all commits with displayed revision, user, date, file, log message)
  • $ svn move OLDPATH NEWPATH: renames and/or moves a file or directory from OLDPATH to NEWPATH
  • $ svn update PATH (update can be shortened to up): updates the local copy with data from the remote repository
  • $ svn help: lists all available commands

Command Options

SVN commands are often run with some options (in the above list the option -m is used with the commit command). All options exist in the same namespace so their meaning is similar no matter with which command they are used. SVN won’t run commands with invalid options but will exit with error message in such cases. In SVN there is no strict “word order” so options can appear anywhere after the $ svn declaration. Here’s a list of some commonly used options:

  • --username NAME: provides a username to log in a SVN server
  • --password PASS: provides a password to log in
  • --config-dir DIR: sets different from the default directory to read configuration information from
  • --accept ACTION: sets an action for automatic conflict resolution. The available actions are:
    • postpone (p): no action. The conflicts will be resolved later
    • edit (e): conflicted files will be opened in a text editor
    • launch (l): launches an interactive merge conflict resolution tool
    • base: chooses the file with the unmodified revision before integrating changes from the remote server into the local copy
    • working: chooses the file as it is in the local copy
    • mine-full (mf): preserves all local modifications
    • theirs-full (tf): keeps all the modifications fetched from the remote repository
    • mine-conflict (mc): prefers all local modifications
    • theirs-conflict (tc): prefers all the modifications fetched from the remote repository
  • --help (-h) (-?): displays the help information for the command
  • --message (-m) MESSAGE: provides a message for a commit or lock
  • --verbose (-v): running a command with -v causes the SVN client to give complete information about the current state and actions
  • --show-updates (-u): displays information about out of date files (the files that will be updated if the update command is run)

Was this post helpful?