SVN is a centralized version control system. SVN Commands Svn Commands

Introduction

The help function of Subversion ( svn help) provides a summary of the available commands. More detailed information is available from the Subversion on-line book available at http://svnbook.red-bean.com/en/1.2/index.html. Chapter 3 is especially helpful.

The following is a basic set of commands which all editors will use frequently. Some commands have two forms, the long and the short. Both are listed in the description.

svn diff. This is useful for two different purposes. First, those without write access to the BLFS SVN server can use it to generate patches to send to the BLFS-Dev mailing list. To do this, simply edit the files in your local sand box then run svn diff > FILE.patch from the root of your BLFS directory. You can then attach this file to a message to the BLFS-Dev mailing list where someone with editing rights can pick it up and apply it to the book. The second use is to find out what has changed between two revisions using: svn diff -r revision1:revision2 FILENAME . For example: svn diff -r 168:169 index.xml will output a diff showing the changes between revisions 168 and 169 of index.xml .

Subversion (SVN - Concurrent Versions System) - centralized system version control. Designed as a replacement for CVS, has the same functionality, but lacks many of its disadvantages. See also: SVN book.

Setting up an SVN server

SVN repository, quite simple, in in this example, directory, /home/svn/, must exist: # svnadmin create --fs-type fsfs /home/svn/project1 You can connect to the repository in the following ways:

  • file://- Direct access through the file system using SVN client. Privileges must be set correctly on the local file system.
  • svn:// or svn+ssh:// - Remote access To SVN server (also according to the protocol SSH). Requires rights in the local file system, default port: 2690/tcp.
  • http:// Remote access via webdav using apache. This method does not require local users.
Import and check an existing project through the local file system. It is not necessary to go into the working directory, you can simply specify the full path: # svn import /project1/ file:///home/svn/project1/trunk -m "Initial import" # svn checkout file:///home/svn/project1

Remote access via SSH protocol

Remote access via protocol SSH does not require any additional settings, just replace file:// on svn+ssh/hostname. For example: # svn checkout svn+ssh://hostname/home/svn/project1 As in the case of local access, the user must have an account to access via the protocol SSH to the server, and correctly configured read/write permissions. This method may be suitable for small groups of users, the users in the group are the owners of the repository, for example: # groupadd subversion # groupmod -A user1 subversion # chown -R root:subversion /home/svn # chmod -R 770 /home/svn

Remote access via HTTP(apache)

Remote access via HTTP(HTTPS), a suitable solution for remote user groups. This method uses web server authentication Apache(not local accounts). Here is a typical configuration: LoadModule dav_module modules/mod_dav.so LoadModule dav_svn_module modules/mod_dav_svn.so LoadModule authz_svn_module modules/mod_authz_svn.so # For access control only DAV svn # URL "/svn/foo" will be mapped to the repository path /home/svn/foo SVNParentPath /home/svn AuthType Basic AuthName "Subversion repository" AuthzSVNAccessFile /etc/apache2/svn.acl AuthUserFile /etc/apache2/svn- passwd Require valid-user Server Apache must have full access to the repository: # chown -R www:www /home/svn Create a user using htpasswd: # htpasswd -c /etc/svn-passwd user1 #-c Create file

Access control svn.acl example

# Default read access. "* =" will not have access by default[/] * = r project1-developers = joe, jack, jane # Give write permissions to developers@project1-developers=rw

Some commands for managing SVN repository

See also Subversion Quick Reference Card. Tortoise SVN, a good Windows interface.

Import

Import to repository new project containing directories and files, you can use the command import. The same command is also used to add a directory with its contents to an already existing project. # svn help import # Help on command # Add a new directory and its contents to the src directory of project1.# svn import /project1/newdir http://host.url/svn/project1/trunk/src -m "add newdir"

Typical SVN Commands

# svn co http://host.url/svn/project1/trunk # Place an order for latest version # Tags and branches are created using copying# svn mkdir http://host.url/svn/project1/tags/ # Create a tags directory# svn copy -m "Tag rc1 rel." http://host.url/svn/project1/trunk \ http://host.url/svn/project1/tags/1.0rc1 # svn status [--verbose] # Check the status of files in the working directory# svn add src/file.h src/file.cpp # Add two files# svn commit -m "Added new class file" # Send changes by message# svn ls http://host.url/svn/project1/tags/ # List of all tags# svn move foo.c bar.c # Move (rename) files# svn delete some_old_file # Delete files

This series of articles is devoted to the introduction to use SVN, from point of view regular user. The article was written to help my colleagues quickly learn and use SVN. So let's start with the basics.

Introduction

Subversion ( SVN) is a free and open source version control system. SVN allows you to manage files and directories, as well as changes made to them over time. SVN provides the following features:

  1. Control of directory changes. SVN uses a "virtual" file system with versioning capabilities that is capable of tracking changes over time to entire directory structures
  2. True story versions. SVN makes it possible to add, delete, copy and rename both files and directories. Moreover, each newly added file begins life from scratch, maintaining its own history of changes
  3. Atomic commit of changes. Each set of changes either ends up in the repository entirely, or does not end up there at all. Those. if, when committing project changes, an error occurred during file processing, then the changes to the entire project will not be committed
  4. Metadata with versions. Each file and directory has its own set of properties, represented by a name and a value. You can create and save any necessary pairs of property names and their values. File properties are just as versioned as their contents
  5. A unified way of working with data. SVN detects differences between files using a special binary algorithm that works equally with both text and binary files. Files are written to storage in a compressed form regardless of their type, and differences between individual versions can be transmitted over the network in both directions
  6. Effective branches and tags. SVN creates branches and tags by simply copying a project, using a mechanism similar to hard links in file systems. Thanks to this, the operations of creating branches and tags take little time.


List of basic terms

  1. Repository(repository) is a centralized repository of source codes, working materials and documentation. Any number of clients connect to the storage and read or write these files
  2. Working copy/working copy(WC) is a regular tree of directories on a computer containing a set of files for working on a project. Changes to the working copy are not available to other users of the repository until they are committed.
  3. Trunk— main direction of development
  4. Branch(“Branch”) is a development direction that exists independently of another direction, but has a common history with it. A branch always starts as a copy of something and moves from that point, creating its own history
  5. Tag(“Label”) is an explicitly selected version of the project files at a certain point in time, through the creation of a separate folder.
  6. Revision— revision number of the repository, within the repository the revision number is a unique value
  7. Checkout- a team that performs the initial receipt of the project from the repository in WC.
  8. Commit- a command that commits changes to project files in WC to the Repository.
  9. Update- a command that updates project files in WC from the repository
  10. Revert- a command that undoes any changes to project files in WC based on the repository revision number.
  11. Merge- a command that merges files from different branches of the project and places the merge result in WC.
  12. Conflict- a situation that arises when committing changes, when the same files were changed by several developers.
  13. Resolve- a set of rules for resolving emerging conflicts.
  14. Import- a command for quickly copying a tree of files to the Repository.
  15. Export- the command for exporting a project differs from checkout in that it does not create service information in the project folders.
  16. Switch- a command that switches WC to another development branch.
  17. Create, Add, Delete, Copy, Move, Rename- commands for managing files and folders in the repository or WC.

Software

Working with the repository SVN reviewed based on software TortoiseSVN

Extract

Svn checkout [-depth ARG] [--ignore-externals] [-r rev] URL PATH

If the checkbox is checked Skip external

If you are retrieving a specific revision, specify it after the URL using the -r parameter.

Update

Svn info URL_working_copy svn update [-r rev] PATH

Updating multiple items is not currently an atomic operation in Subversion. Therefore, TortoiseSVN first finds the leading revision (HEAD) in the repository and then updates all items to that revision to avoid creating a working copy with mixed revisions.

If only one item is selected to update, or the selected items are not all from the same repository, TortoiseSVN simply updates to the leading revision.

No command line options are used here. Update to revision also implements the update command, but offers more functionality.

Update to revision

Svn info URL_working_copy svn update [-r rev] [-depth ARG] [--ignore-externals] PATH

The depth combo box items relate to the -depth argument.

If the checkbox is checked Skip external, use the --ignore-externals option.

Fix

In TortoiseSVN, the commit dialog uses several Subversion commands. The first stage is a status check, which identifies elements of your working copy that could potentially be committed. You can browse this list, compare the files to their base, and select the items you want to include in the commit.

Svn status -v PATH

If the checkbox is checked

If you mark any unversioned files and folders, those items will be added to your working copy first.

Svn add PATH...

When you click OK, Subversion begins executing the commit. If you leave all file checkboxes in their default state, TortoiseSVN uses a single recursive commit of the working copy. If you have unmarked some files then non-recursive commit (-N) should be used and each path should be specified individually in command line for fixation.

Svn commit -m "LogMessage" [-depth ARG] [--no-unlock] PATH...

The LogMessage here represents the contents of the log message input field. It may be empty.

Difference

Svn diff PATH

If you use the Diff command from the main context menu, you compare the modified file with its base revision. The output from the ICS of the above command also does this and produces output in the format of combined differences. However, TortoiseSVN does not use this. TortoiseSVN uses TortoiseMerge (or a diff program of your choice) to visually display differences between text files, so there is no direct equivalent to SVN.

You can also compare any two files using TortoiseSVN, regardless of whether they are under version control. TortoiseSVN simply feeds these two files into the chosen diff program and lets it determine where the differences are.

Magazine

Svn log -v -r 0:N --limit 100 [--stop-on-copy] PATH or svn log -v -r M:N [--stop-on-copy] PATH

By default, TortoiseSVN tries to extract 100 log messages using the --limit method. If installations are forced to use the old APIs, then the second form is used to retrieve log messages for 100 revisions from the repository.

If the checkbox is checked Stop at copy/rename, use the --stop-on-copy option.

Checking for changes

Svn status -v PATH or svn status -u -v PATH

The initial status check looks only at your working copy. If you click on Check storage, then the repository is also checked to see which files will be changed by the update, and this requires the -u option.

If the checkbox is checked Show unversioned files, TortoiseSVN will also show unversioned files and folders in the working copy hierarchy, respecting the ignore rules. This particular property has no direct equivalent in Subversion, since the svn status command does not go into unversioned folders.

Revision graph

The revision graph is a feature provided only by TortoiseSVN. There is no equivalent in the command line client.

What TortoiseSVN does:

Svn info URL_working_copy svn log -v URL

where URL is root storage, and then parses the returned data.

Storage Explorer

Svn info Working_copy URL svn list [-r rev] -v URL

You can use svn info to define the repository root: this is the top level displayed in the repository browser. You cannot move above this level. Also, this command returns all lock information displayed in the Storage Explorer.

Calling svn list will list the contents of the folder, for the specified URL and revision.

Edit conflicts

This command has no equivalent in ICS. It calls TortoiseMerge or external tool three-way diff/merge to view the files involved in the conflict and select the lines that should be used.

Settled

Svn resolved PATH

Rename

Svn rename CURRENT_PATH NEW_PATH

Delete

Svn delete PATH

Remove changes

Svn status -v PATH

The first stage is a status check, identifying items in your working copy that could potentially have changes removed. You can view the list, compare files with the database and select elements in which you want to remove changes.

When you click OK, Subversion will remove the changes. If you leave all file selection flags in their default state, TortoiseSVN uses a single recursive (-R) undo of changes to the working copy. If you uncheck some files, then each path must be specified individually on the command line to remove the changes.

Svn revert [-R] PATH...

Cleaning

Svn cleanup PATH

Block

Svn status -v PATH

The first stage is a status check, which identifies files in your working copy that could potentially be locked. You can select the items you want to block.

Svn lock -m "LockMessage" [--force] PATH...

LockMessage is the content of the lock message field. It may be empty.

If the checkbox is checked Intercept locks, use the --force option.

Unblocking

Svn unlock PATH

Branch/Label

Svn copy -m "LogMessage" URL URL or svn copy -m "LogMessage" or svn copy -m "LogMessage" PATH URL

The Branch/Label dialog performs a copy to the storage. There are 3 switchable buttons:

  • Leading revision in the repository (HEAD)
  • The specified revision in the repository
  • Working copy

which correspond to the three command line options above.

add – Adds files, directories and symbolic links, marking them for later inclusion in the repository. Once marked, they are downloaded and added to the repository the first time the changes are committed. If you added something, but then changed your mind before pinning it, you can remove the add mark using the svn revert subcommand.
svn add PATH...
$svn add testdir

blame (praise, annotate, ann) – Shows the author and editor line by line for the specified files or URLs. Each line of text begins with the author's name (username) and revision number. This indicates who and when last modified this line.
svn blame TARGET[@REV]…
$ svn blame http://svn.red-bean.com/repos/test/readme.txt

cat – Prints the contents of specified files or URLs. To list the contents of directories, use svn list.
svn cat TARGET[@REV]…
$ svn cat http://svn.red-bean.com/repos/test/readme.txt

checkout (co) – Creates a working copy based on the data in the repository. If PATH is omitted, the base name of the URL will be used as the name for the working copy directory. If multiple URLs are given, corresponding copies will be created in the PATH subdirectory, each in its own directory derived from the base name of the URL.
svn checkout URL[@REV]…
svn checkout svn://svn.ru2web.ru/ru2web/branches/www-01/ /usr/home/vasia/ru2web.ru/app/

cleanup – Recursively cleans the working copy, removing locks remaining from uncompleted operations. As soon as you encounter the "working copy is locked" error, run this subcommand to remove old locks and bring the working copy into a working state.

If for some reason the operation of the svn update command failed due to problems with the running external diff program (for example, I clicked something wrong in it or there was a network failure), you need to set the –diff3-cmd parameter to allow the copy to be cleaned to complete all joins using an external diff program. You can also specify the configuration directory using the –config-dir option, but be careful not to overuse these options.

commit (ci) – Sends the changes you made to the working copy to the repository to be saved there. If you do not use either the –file or –message option, svn will launch an external editor to compose the comment. Read the description of the editor-cmd parameter in "Config".
svn commit will send all recursively found lock labels to the storage facility and unlock the resources corresponding to these labels if the –no-unlock parameter was not specified. The “search area” is specified by specifying PATH.
svn commit

copy (cp) – Copies a file into a working copy or to storage. SRC and DST can be paths inside the working copy or URLs inside the repository.
svn copy SRC DST

delete (del, remove, rm) – Deleting an item from a working copy or repository.
svn delete PATH...
svn delete URL...

diff (di) – Shows the differences between the working copy and the repository.
$ svn diff http://svn.collab.net/repos/svn/trunk/COMMITTERS@3000 http://svn.collab.net/repos/svn/trunk/COMMITTERS@3500

export – Export a clean directory tree (without .svn folders).

help (?, h) – Help.

import – Commits an unversioned file or tree to the repository.
svn import URL

info – Display information about a local or remote element.
svn info

list (ls) – List of directories in the repository.
svnlist...]
$ svn list http://svn.red-bean.com/repos/test/support

lock – Lock the working copy in the repository so that no other user can make changes to the given path.
svn lock TARGET…
$ svn lock tree.jpg house.jpg

log – Show log messages.
svnlog
svn log URL
$svnlog

merge – Apply differences between two sources.
$ svn merge -r 250:HEAD http://svn.red-bean.com/repos/branches/my-branch

mkdir – Create a directory in a version controlled repository.
$svn mkdir newdir

move (mv, rename, ren) – Move a file or directory.
svn move SRC DST

propdel (pdel, pd) – Remove properties from files, directories or revisions.
svn propdel PROPNAME
svn propdel PROPNAME –revprop -r REV

propedit (pedit, pe)
propget (pget, pg)
proplist (plist, pl)
propset (pset, ps)

resolved – Remove “conflicts” from the working copy of files or directories.
svn resolved PATH…

revert – Revert all local changes.
$ svn revert myprj.phtml

status (stat, st) – Status of the working copy of files or directories.
$svn status wc

switch (sw) – Update the working copy to a different URL.

unlock – Unlocks the working copy.

update (up) – Updating your working copy.