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"
- Add the directory, while ignoring all of the files it contains:
- svn propedit svn:ignore calculator (=dir)
- calculator
debug_log* - -> ignores the file "calculator" and "debug_log*" in dir "calculator"
- 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/
- svn propedit svn:externals plugins
- svn up
Alternative using the command line:
- svn propset svn:externals "MyPlugin http://www.example.com/svn/MyPlugin/trunk" plugins
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)
- svn mkdir -m "layout creation" http://www.example.com/svn/myProject/trunk http://www.example.com/svn/myProject/tags http://www.example.com/svn/myProject/branches
Recover a deleted file
- Find out in which revision you deleted the file (e.g. 34)
- Call the following 'svn copy' command with the previous revison (e.g. 34-1=33)
- svn copy -r 33 http://www.example.com/svn/myProject/trunk/myDirectory/myFile.php http://www.example.com/svn/myProject/trunk/myDirectory/myFile.php
Revert to a previous revision (undo)
- svn merge -r 459:458 http://bigfish.ull.at/svn/ullright/trunk
- check merge
- commit
Revert a single file to a previous revision
- cd myDirectory/
- svn export -r 26 http://www.example.com/svn/myProject/trunk/myDirectory/myFile.php
Branching
- http://blog.evanweaver.com/articles/2007/08/15/svn-branching-best-practices-in-practice/
- http://svnbook.red-bean.com/en/1.1/re27.html
- http://svnbook.red-bean.com/en/1.1/ch04s05.html
- Subversion does not support cross-repository copying. When using URLs with svn copy or svn move, you can only copy items within the same repository.
create branch
-
svn http://server/path/to/trunk http://server/path/to/branch/myBranch -m "Created branch 'myBranch'"
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:
- svn merge -h 1234:HEAD http://server/path/to/branch
change repository url
- svn switch --relocate
Temporarily switch to an older revision
- svn up -r 1234
Subversion Client for Windows:
- Homepage: http://tortoisesvn.tigris.org/
- Download: http://tortoisesvn.net/downloads
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
* =
- [groups]
@localhost
- cd .../myProjectDir
- svn mkdir -m "layout creation" http://www.example.com/svn/myRepoName/trunk
- svn import -m "initial import" . http://www.example.com/svn/myRepoName/trunk
- cd ..
- mv myProjectDir myProjectDir.origin
- mkdir myProjectDir
- cd myProjectDir
- svn co http://www.example.com/svn/myRepoName/trunk .
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 * =