subversion svn cheat sheet

For Eclipse subversion stuff see Eclipse cheat sheet

 

Status Codes:  

  •  A - Added
  • D - Deleted
  • U - Updated
  • M - Modified
  • C - Conflict
  • G - Merged
  • R - Replaced
  • I - Ignored
  • X - External 

 

Useful svn commands:

  • svn info -> displays repository information, actual build number, ...
  • svn stat -> displays status of the files (see status codes above)
  • svn update -> get files from repository
  • svn add filename.php -> mark a file or directory to be added to the repository
  • svn mv filename1.php filename2.php -> "rename"
  • svn rm filename.php -> delete a file
  • svn commit -m "describe the changes" -> upload the files to the repository
  • svn log -> "show changelog"
  • svn diff -r 100 form_custom_fields.inc -> compare current version with version from release 100

Remove missing files with ! (exclamation mark)

  • svn st | grep ^! | awk '{$1=""; print " --force \""substr($0,2)"@\"" }' | xargs svn rm
  • svn st | grep ! | cut -d! -f2| sed 's/^ *//' | sed 's/^/"/g' | sed 's/$/"/g' | xargs -i svn rm --force "{}"

Checkout with svn+ssh:

  • svn checkout svn+ssh://myuser@myserver.example.com/var/lib/subversion/public/myrepo/trunk/custom/ .

Ignore:

  • ignore directory contents
    • Add the directory, while ignoring all of the files it contains:
      svn add -N [directory]
    • After adding the directory enter the directory and run the following command:
      svn propset svn:ignore '*.*' .
    • Commit your changes:
      svn commit -m "Added the directory and set the files within it to be ignored"
  • svn propedit svn:ignore calculator (=dir)
    • calculator
      debug_log*
    • -> ignores the file "calculator" and "debug_log*" in dir "calculator"
  • svn propedit svn:ignore .
    • config
    • -> ignores root level dir "config"
  • svn stat --no-ignore
    • -> shows files that are ignored by svn ci etc

Remove from repro and ignore

  • svn rm --keep-local example.txt
  • svn ci ...
  • ignore example.txt with gui

Externals:

Example for plugins/MyPlugin/

Alternative using the command line:

Load list from file:

  • svn propset svn:externals . -F /tmp/svnext.txt

Delete all .svn files: 

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

Create directories in the repository (Layout)

Recover a deleted file

Revert to a previous revision (undo)

Revert a single file to a previous revision

Branching

create branch

update branch with changes from trunk

  • svn log --stop-on-copy
    • -> get revision of branch creation (or last update?) (e.g. 34)
  • svn merge --dry-run -r34:HEAD http://server/path/to/trunk

merge branche into trunk

In the working copy of trunk:

change repository url

  • svn switch --relocate   

Temporarily switch to an older revision

  • svn up -r 1234

Subversion Client for Windows:


Install subversion server using apache

  • sudo mkdir /var/lib/subversion/public -p
  • sudo aptitude install subversion libapache2-svn
  • sudo vi /etc/apache2/mods-available/dav_svn.conf
    •    DAV svn   SVNParentPath /var/lib/subversion/public   AuthType Basic   AuthName "Subversion Repository"   AuthUserFile /etc/apache2/dav_svn.passwd   # If you want more complex access rights enable dav_svn_authz   AuthzSVNAccessFile /etc/apache2/dav_svn.authz   Require valid-user 
  • sudo htpasswd -c /etc/apache2/dav_svn.passwd my_username
  • sudo chown www-data /etc/apache2/dav_svn.passwd
  • sudo chmod 600 /etc/apache2/dav_svn.passwd
  • sudo apache2ctl restart

 

Create repository

@svn server:

  • cd /var/lib/subversion/public
  • sudo svnadmin create myRepoName
  • sudo chown www-data:www-data * -R
  • htpasswd /etc/apache2/dav_svn.passwd klemens
  • sudo vi /etc/apache2/dav_svn.authz
    • [groups]
      ...
      myRepoName-developers = klemens

      [myRepoName:/]
      @myRepoName-developers = rw
      * =

@localhost

 


Migrate repository

for example if the berkly db version changes during a server update

http://svnbook.red-bean.com/en/1.2/svn.reposadmin.maint.html#svn.reposadmin.maint.migrate

 

old server:

  • svnadmin dump /var/lib/subversion/public/myrepo > svn.dumpfile

new server:

 

  • cd /var/lib/public
  • scp -r root@oldserver:/root/svn.dumpfile .
  • svnadmin create myrepo
  • svnadmin load myrepo < svn.dumpfile
  • + set file rights

completely delete files from the repository

  • cd /var/lib/subversion/public
  • svnadmin dump ullright > ullright.svn.dump
  • svndumpfilter exclude trunk/data/fixtures/test < ullright.svn.dump > ullright.svn.dump.fixed
  • mv ullright ullright.backup
  • svnadmin create ullright
  • svnadmin load ullright < ullright.svn.dump.fixed
  • copy commit-hooks etc

 


svn backup

  • #!/bin/bash
    #
    # by klemens ullmann 2008-04-25
    #
    
    REPOSPATH="/var/lib/subversion/public"
    BACKUPPATH="/backup/subversion"
    
    # sed is used to delete blank lines
    
    FILES=`find $REPOSPATH -maxdepth 1 -type d -printf %P"
    " | sed '/^$/d'`
    for f in $FILES; do
        svnadmin dump $REPOSPATH/$f > $BACKUPPATH/$f.svn.dumpfile
    done

svn load dumpfile

  • #!/bin/bash
    # migrationscript for subversion
    # by klemens ullmann 2008-05-09
    #
    
    REPOSPATH="/var/lib/subversion/public"
    
    # copy backup dumps from old server
    rsync -avz --stats --progress --delete root@oldserver:/srv/backup/subversion /tmp/
    
    FILES=`find /tmp/subversion -maxdepth 1 -type f -printf %P"
    " | sed 's/.svn.dumpfile//g'`
    
    for f in $FILES; do
        echo Loading svn repository /tmp/subversion/$f
        svnadmin create $REPOSPATH/$f
        svnadmin load $REPOSPATH/$f < /tmp/subversion/$f.svn.dumpfile
    done

Make parts of a public repository private

Assumes that anonymous svn access is disabled and a "guest" user is used.

/etc/apache2/dav_svn.authz

[ullright:/]
@ullright-developers = rw
* = r

[ullright:/trunk/plugins/secretPlugin]
@ullright-developers = rw
* =