Subversion Basic Commands

From HaFrWiki
Jump to: navigation, search

The following cheat sheet gives you the basic commands of Subversion Version Control System [1].
There are 2 work-flow examples. The second version is more convenient to use.

Short description[edit]

First create a folder on the desired hard disk to contain the versionized version to keep the data.

  • svnadmin create <VersionName>

Example:

  • svnadmin create z:\usr\svndata\B-One\FJR

Next goto the directory containing the data and import the data


Configuration[edit]

Subversion creates a configuration file config when the first time the svn command is used. The location of this file depends on you OS.

  • Windows: The config file is located in the %APPDATA%\Subversion directory.
  • UNIX: The config file is located in user environment under the name .subversion.


Basic Work Cycle[edit]

top The basic works styles has 2 examples to create a new repository. The First example is more explicable if you are new to SVN, while the second example is more easier to use in practice.

Summary[edit]

The action in summary below are based on 2 NAS drives:

  • New: LaCie 2big Raid 1
  • Old: LaCie Edmini (deceased and deprecated)
Action How Example
Create a repository. svnadmin create  new > svnadmin create z:\vcs\svn\<repodir>
 old > svnadmin create z:\usr\svndata\<repodir>
Import the existing files svn import  new > svn import -m "Intro" c:\<local dir> file:///z:/vcs/svn/<repodir>
 old > svn import -m "Intro" c:\<local dir> file:///z:/usr/svndata/<repodir>
Remove the local dir content. Command line copy and del.  both  > copy c:\<local dir> %tmp%
 > del *.*
Checkout the content of the repo.
NB: 1 dir above the <local dir>!
svn checkout  new > cd..
 > svn co file:///z:/vcs/svn/<repodir>
 old > cd..
 > svn co file:///z:/usr/svndata/<repodir>

Example[edit]

top

F:\Projects>svnadmin create z:\usr\svndata\projects\ASR


F:\Projects>svn import -m "Intro" f:\Projects\ASR file:///z:/usr/svndata/Projects/ASR

Adding         F:\Projects\ASR\Meeting_20090710.txt

Committed revision 1.


F:\Projects>cd ASR
F:\Projects\ASR>copy *.* %TMP%

Meeting_20090710.txt
        1 file(s) copied.


F:\Projects\ASR>del *.*
F:\Projects\ASR\*.*, Are you sure (Y/N)? y

F:\Projects\ASR>cd ..
F:\Projects>svn co file:///z:/usr/svndata/projects/ASR

A    ASR\Meeting_20090710.txt
Checked out revision 1.


F:\Projects>cd ASR

F:\Projects\ASR>dir

 Volume in drive F is LACIE250
 Volume Serial Number is 6853-5BA9

 Directory of F:\Projects\ASR

07/10/2009  11:35 AM    <DIR>          .
07/10/2009  11:35 AM    <DIR>          ..
07/20/2009  04:23 PM    <DIR>          .svn
07/20/2009  04:23 PM             1,052 Meeting_20090710.txt
               1 File(s)          1,052 bytes
               3 Dir(s)  143,475,539,968 bytes free

Example 2[edit]

top

Syncro SVN Client Check-Out

Another (more simple) way of creating a new repository is described below. In this example a GUI-tools called Syncro Client [2] is used. The steps to follow are:

  • First create a new repository using the svnadmin tool of your subversion installation:
    svnadmin create z:\vcs\svn\<repo-name>.
    Please note that the repo has to be created on the filesystem. An URL can not be created!
  • In Syncro Client: Create a new repository location
     Repository  -  New Repository Location .
  • In Syncro Client: Add the name of the repository into the Popup Window:
    Window title  Add SVN Repository , Label  Repository URL:  
    file:///z:/vcs/svn/< repo-name>
    or
    http://harm/svn/< repo-name>
  • In Syncro Client: CheckOut of this new created repository.
    Right-Mouse-Click on the <repo-name> in the View  Repository view  and choose  Check out...  . See Image on the right side.
  • In the Pop-up Windows as shown on the right: In the Section   Target - Folder:   type the name of the existing folder containing the files to be checked in.
    f:\<repo-name>.
  • In the view  Working copy  a new Working copy has been created. Edit the settings. by using the icon for  Add/Remove Working Copy .
  • In Syncro Client: Open Working Copy
  • In Syncro Client: Add files to repository
  • In Syncro Client: Commit your changes.

Expanded[edit]

The first action to take is to create a repository by using the svnadmin create command.

 > svnadmin create z:\usr\svndata\<repodir>

Import the existing files into the repository using the svn import command.

 > svn import -m "Intro" c:\<local dir> file:///z:/usr/svndata/<repodir>

Remove the content from the local directory into a temp dir. Then do a checkout using svn checkout in the directory above the local dir:

> svn co file:///z:/usr/svndata/<repodir>

Adding new created files to an already existing directory use the svn add command:

 > svn add *.* --force

Summary top

Create repository[edit]

Name svnadmin create — Create a new, empty repository.
Synopsis svnadmin create REPOS_PATH
Description Create a new, empty repository at the path provided. If the provided directory does not exist, it will be created for you.[55] As of Subversion 1.2, svnadmin creates new repositories with the fsfs filesystem backend by default.
Switches --bdb-txn-nosync

--bdb-log-keep
--config-dir DIR
--fs-type TYPE

Examples Creating a new repository is just this easy:
 $ svnadmin create /usr/local/svn/repos
 > svnadmin create \usr\local\svn\repos

In Subversion 1.0, a Berkeley DB repository is always created. In Subversion 1.1, a Berkeley DB repository is the default repository type, but an FSFS repository can be created using the --fs-type option:

 $ svnadmin create /usr/local/svn/repos --fs-type fsfs
 > svnadmin create z:\usr\svndata\repos --fs-type fsfs

Summary top

Importing files[edit]

Name svn import — Commit an unversioned file or tree into the repository.
Synopsis svn import [PATH] URL
Description Recursively commit a copy of PATH to URL. If PATH is omitted “.” is assumed. Parent directories are created in the repository as necessary.
Alternate Names None
Changes Repository
Accesses Repository Yes
Switches --message (-m) TEXT
--file (-F) FILE
--quiet (-q)
--non-recursive (-N)
--username USER
--password PASS
--no-auth-cache
--non-interactive
--force-log
--editor-cmd EDITOR
--encoding ENC
--config-dir DIR
--auto-props
--no-auto-props
--ignore-externals
Examples This imports the local directory myproj into the root of your repository:
 $ svn import -m "New import" myproj http://svn.red-bean.com/repos/test
 Adding         myproj/sample.txt
 ...
 Transmitting file data .........
 Committed revision 16.

This imports the local directory myproj into trunk/misc in your repository. The directory trunk/misc need not exist before you import into it—svn import will recursively create directories for you:

 $ svn import -m "New import" myproj http://svn.red-bean.com/repos/test/trunk/misc/myproj
 Adding         myproj/sample.txt
 …
 Transmitting file data .........
 Committed revision 19.

After importing data, note that the original tree is not under version control. To start working, you still need to svn checkout a fresh working copy of the tree.

 > svn import c:\test file:///z:/usr/svndata/test
 Adding         C:\test\test
 Skipped 'C:\test\test\.svn'
 Adding         C:\test\test\example.xml
 Skipped 'C:\test\.svn'
 Adding         C:\test\example.xml
 Committed revision 1.

Summary top

Adding new files[edit]

Name svn add — Add files, directories, or symbolic links.
Synopsis svn add PATH...
Description Add files, directories, or symbolic links to your working copy and schedule them for addition to the repository. They will be uploaded and added to the repository on your next commit. If you add something and change your mind before committing, you can unschedule the addition using svn revert.
Alternate Names None
Changes Working Copy
Accesses Repository No
Switches --targets FILENAME
--non-recursive (-N)
--quiet (-q)
--config-dir DIR
--auto-props
--no-auto-props
--force
Examples To add a file to your working copy:
 $ svn add foo.c 
 A         foo.c

When adding a directory, the default behavior of svn add is to recurse:

 $ svn add testdir
 A         testdir
 A         testdir/a
 A         testdir/b
 A         testdir/c
 A         testdir/d

You can add a directory without adding its contents:

 $ svn add --non-recursive otherdir
 A         otherdir

Normally, the command svn add * will skip over any directories that are already under version control. Sometimes, however, you may want to add every unversioned object in your working copy, including those hiding deeper down. Passing the --force option makes svn add recurse into versioned directories:

 $ svn add * --force
 A         foo.c
 A         somedir/bar.c
 A         otherdir/docs/baz.doc

Summary top

Checkout repository[edit]

Name svn checkout Check out a working copy of a repository.
Synopsis svn co URL[@rev] ... [PATH].
Description Check out a working copy from a repository. If PATH is omitted, the basename of the URL will be used as the destination. If multiple URLs are given, each will be checked out into a subdirectory of PATH, with the name of the subdirectory being the basename of the URL.
Alternate Names co
Changes Creates a working vopy
Accesses Repository Yes
Switches --depth ARG
--force
--ignore-externals
--quit (-q)
--revision (-r) REV
Examples Check out a working copy into a directory called mine
 $ svn co file:///var/xxx mine
 > svn co file:///z:/xxx mine
 A         mine/a
 A         mine/b
 Check out revision 20
 $ ls
 mine

Check out with a revision indication:

 $ svn checkout -r 2 file:///var/xxx mine
 > svn checkout -r 2 file:///z:/xxx mine
 A          mine/a
 Checked out revision 2.

Summary top

Commit changes[edit]

Name svn commit — Send changes from your working copy to the repository.
Synopsis svn commit [PATH...] {-m "logmessage}"
Description Send changes from your working copy to the repository. If you do not supply a log message with your commit by using either the --file or --message switch, svn will launch your editor for you to compose a commit message. See the editor-cmd section in the section called Config.
svn commit will send found lock tokens and release locks on all PATHS committed (recursively) unless --no-unlock is passed.
Tip: If you begin a commit and Subversion launches your editor to compose the commit message, you can still abort without committing your changes. If you want to cancel your commit, just quit your editor without saving your commit message and Subversion will prompt you to either abort the commit, continue with no message, or edit the message again.
Alternate Names ci (short for “check in”; not “co”, which is short for “checkout”)
Changes Working copy, repository
Accesses Repository Yes
Switches --message (-m) TEXT
--file (-F) FILE
--quiet (-q)
--no-unlock
--non-recursive (-N)
--targets FILENAME
--force-log
--username USER
--password PASS
--no-auth-cache
--non-interactive
--encoding ENC
--config-dir DIR
Examples Commit a simple modification to a file with the commit message on the command line and an implicit target of your current directory (“.”):
 $ svn commit -m "added howto section."
 Sending        a
 Transmitting file data .
 Committed revision 3.

Commit a modification to the file foo.c (explicitly specified on the command line) with the commit message in a file named msg:

 $ svn commit -F msg foo.c
 Sending        foo.c
 Transmitting file data .
 Committed revision 5.

If you want to use a file that's under version control for your commit message with --file, you need to pass the --force-log switch:

 $ svn commit --file file_under_vc.txt foo.c
 svn: The log message file is under version control
 svn: Log message file is a versioned file; use '--force-log' to override
 
 $ svn commit --force-log --file file_under_vc.txt foo.c
 Sending        foo.c
 Transmitting file data .
 Committed revision 6.

To commit a file scheduled for deletion:

 $ svn commit -m "removed file 'c'."
 Deleting       c
 Committed revision 7.

Summary top

Update work copy[edit]

Name svn update Update your working copy.
Synopsis svn update [PATH...]
Description svn update brings changes from the repository into your working copy. If no revision given, it brings your working copy up-to-date with the HEAD revision. Otherwise, it synchronizes the working copy to the revision given by the --revision switch. As part of the synchronization, svn update also removes any stale locks (see the section called “Sometimes You Just Need to Cleanup”) found in the working copy.
For each updated item a line will start with a character reporting the action taken. These characters have the following meaning:
  • A Added
  • D Deleted
  • U Updated
  • C Conflict
  • G Merged

A character in the first column signifies an update to the actual file, while updates to the file's properties are shown in the second column.

Alternate Names up
Changes Working copy
Accesses Repository Yes
Switches --revision (-r) REV
--non-recursive (-N)
--quiet (-q)
--diff3-cmd CMD
--username USER
--password PASS
--no-auth-cache
--non-interactive
--config-dir DIR
--ignore-externals
Examples Pick up repository changes that have happened since your last update:
 $ svn update
 A  newdir/toggle.c
 A  newdir/disclose.c
 A  newdir/launch.c
 D  newdir/README
 Updated to revision 32.

You can also update your working copy to an older revision (Subversion doesn't have the concept of “sticky” files like CVS does; see Appendix B, Subversion for CVS Users):

 $ svn update -r30
 A  newdir/README
 D  newdir/toggle.c
 D  newdir/disclose.c
 D  newdir/launch.c
 U  foo.c
 Updated to revision 30.

Tip: If you want to examine an older revision of a single file, you may want to use svn cat.

Summary top

Changes[edit]

Make changes
add foo Schedule file, directory, or symbolic link foo to be added to the repository. When you next commit, foo will become a child of its parent directory. Note that if foo is a directory, everything underneath foo will be scheduled for addition. If you only want to add foo itself, pass the --non-recursive (-N) switch.
delete foo Schedule file, directory, or symbolic link foo to be deleted from the repository. If foo is a file or link, it is immediately deleted from your working copy. If foo is a directory, it is not deleted, but Subversion schedules it for deletion. When you commit your changes, foo will be removed from your working copy and the repository
copy foo bar Create a new item bar as a duplicate of foo. bar is automatically scheduled for addition. When bar is added to the repository on the next commit, its copy history is recorded (as having originally come from foo). svn copy does not create intermediate directories
move foo bar
Also for renaming
This command is exactly the same as running svn copy foo bar; svn delete foo. That is, bar is scheduled for addition as a copy of foo, and foo is scheduled for removal. svn move does not create intermediate directories.

Summary top

Examine[edit]

Examine changes
status Gives you all the information you need regarding what has changed in your working copy without accessing the repository or potentially incorporating new changes published by other users.
More detailed info
dif Another way to examine changes. You can find out exactly how you've modified things by running svn diff with no arguments, which prints out file changes in unified diff format.
revert Reverts the file to its pre-modified state by overwriting it with the cached pristine copy from the .svn area. But also note that svn revert can undo any scheduled operations.
More detailed info

Summary top

Merge[edit]

Merge others changes into your working copy
Update
resolved


See Conflict handling <r>Summary top

Commit[edit]

Commit your changes
Commit Sends all changes to the repository. When you commit a change, you need to supply a log message, describing your change.

Summary top

Results[edit]

Results
Update U foo Update
A foo Added
D foo Deleted
R Foo Replaced
G foo Merged
C foo Committed

Summary top

Detail status info[edit]

1 2 3 4 5 File Description
          file/dir No modifications
    L     some_dir svn left a lock in the .svn area of some_dir
M         bar.c the content in bar.c has local modifications
  M       baz.c baz.c has property but no content modifications
X         3rd_party dir is part of an externals definition
?         foo.o svn doesn't manage foo.o
!         some_dir svn manages this, but it's missing or incomplete. Item is missing (e.g., you moved or deleted it without using svn). This also indicates that a directory is incomplete (a checkout or update was interrupted).
~         qux versioned as file/dir/link, but type has changed
I         .screenrc svn doesn't manage this, and is set to ignore it.
A     +   moved_dir added with history of where it came from
M     +   moved_dir/README added with history and has local modifications
D         stuff/fish.c file is scheduled for deletion
A         stuff/loot/bloo.h file is scheduled for addition
C         stuff/loot/lump.c file has textual conflicts from an update
  C       stuff/loot/glub.c file has property conflicts from an update
R         xyz.c file is scheduled for replacement
        S stuff/squawk file or dir has been switched to a branch
        K dog.jpg file is locked locally; lock-token present
        O cat.jpg file is locked in the repository by other user
        B bird.jpg file is locked locally, but lock has been broken
        T fish.jpg file is locked locally, but lock has been stolen

  © HJM Frielink, last modified: GMT: 06:40, 2019 September 19, Subversion Basic Commands
Summary top

Conflict handling[edit]

Suppose the following:

svn update
U Install.txt
G Readme.txt
C bar.c
Updated to revision 46

The C stands for conflict. Whenever a conflict occurs, three things typically occur to assist you in noticing and resolving that conflict:

  • Subversion prints a C during the update, and remembers that the file is in a state of conflict.
  • If Subversion considers the file to be of a mergeable type, it places conflict markers - strings of text which delimit the sides of the conflict - into the file to visibly demonstrate the overlapping areas. (Subversion uses the svn:mime-type property to decide if a file is capable of contextual, line-based merging.
  • For every conflicted file, Subversion places up to three extra unversioned files in your working copy:
    • filename.mine
      This is your file as it existed in your working copy before you updated your working copy - that is, without conflict markers.
    • filename.rOLDREV
      This is the file that was the BASE revision before you updated your working copy. That is, the file that you checked out before you made your latest edits.
    • filename.rNEWREV
      This is the file that your Subversion client just received from the server when you updated your working copy. This file corresponds to the HEAD revision of the repository.

Here OLDREV is the revision number of the file in your .svn directory and NEWREV is the revision number of the repository HEAD.
Subversion will not allow you to commit the file until the three temporary files are removed.

If you get a conflict, you need to do one of three things:

  • Merge the conflicted text by hand (by examining and editing the conflict markers within the file).
  • Copy one of the temporary files on top of your working file.
  • Run svn revert <filename> to throw away all of your local changes.

Once you've resolved the conflict, you need to let Subversion know by running svn resolved. This removes the three temporary files and Subversion no longer considers the file to be in a state of conflict.

svn resolve bar.c
Resolved conflicted state of 'bar.c'

Summary top

Remove .svn[edit]

To remove all the .svn directories of your checked-out version use:

 find . -name .svn -exec 'rm -rf {}\;'

On my Cygwin installation this does not work, instead use:

 rm -rf `find . -type d -name .svn`

Links[edit]

top

Internal[edit]

top

External[edit]

top

Summary

Reference[edit]

top

  1. Apache Subversion is an open source version control system. Founded in 2000 by CollabNet, Inc., the Subversion project and software have seen incredible success over the past decade. Subversion has enjoyed and continues to enjoy widespread adoption in both the open source arena and the corporate world. The project's original goal of being "a compelling replacement for CVS" (an older version control system with a similar model) was surpassed long ago — today Subversion stands on its own highly reputable name.
  2. Syncro SVN Client Home page. Syncro SVN Client makes easier document and code sharing between content authors or developers. Syncro SVN Client is the best multiplatform SVN client that allows you to browse repositories, check for changes, commit changes, update your working copy and examine the revision history.