最後更新: 2014-10-23
目錄
介紹
Windows Client:
- TortoiseSVN
Web Pannel:
- websvn
- Trac
Server
apt-get install subversion libapache2-svn
mkdir /var/svn
chown -R www-data:www-data /var/svn
vi /etc/apache2/mods-available/dav_svn.conf
基本設定:
<Location /svn> DAV svn SVNParentPath /var/svn # 不同的 project 都是 update svn 目錄 AuthType Basic AuthName "Subversion Repository" AuthUserFile /etc/apache2/dav_svn.passwd AuthzSVNAccessFile /etc/apache2/dav_svn.authz Require valid-user #SSLRequireSSL # this line must be added if you want SSL enabled </Location>
# 另一個 repos.
<Location /svn_poject> DAV svn SVNPath /var/svn-repos/project_zen AuthType Basic AuthName "Subversion Repository" AuthUserFile /etc/apache2/dav_svn.passwd Require valid-user SSLRequireSSL </Location>
a2enmod dav_svn
a2enmod authz_svn
Example:
project: testsvn
User: tester1 r
User: tester2 rw
# add user
htpasswd -c /etc/apache2/dav_svn.passwd tester1
# 降立 svn repository.
svnadmin create /var/svn/testsvn
# conf db format hooks locks README.txt
# 修正 permission
chown -R www-data:www-data /var/svn/testsvn/
# 個別人的權
/etc/apache2/dav_svn.authz
[testsvn:/]
tester1 = r
tester2 = rw
對於 readonly user 會見到
svn: access to '/svn/testsvn/!svn/act/8d325523-4987-4ff5-8878-453e87a8b118' forbidden
成功:
Password for 'tester2': Adding testsvn/file1 Adding testsvn/file2 Adding testsvn/file3 Committed revision 1.
Home Page:
http://subversion.tigris.org/
Apache disallow access to .svn
Setting:
<DirectoryMatch .*\.svn/.*> Deny From All </DirectoryMatch>
OR
RedirectMatch 404 /\\.svn(/|$)
OR
<LocationMatch "\/\..*"> Order allow,deny Deny from all </LocationMatch>
OR
.htaccess
<Directory ~ "\.svn"> Order allow,deny Deny from all </Directory>
Client cmd
svn 的 tools 有
- svn
- svnadmin
- svnlook
- svnserve
svn
svn help
svn help import
svn <subcommand> [options] [args]
Programmer Usage
# 加東西
svn import [ --username <username> --password <pw> ] mytree http://server/svn/project \
-m "Initial import"
失敗的話, 會見到
svn: OPTIONS of 'http://localhost/svn/testsvn': 200 OK (http://localhost)
第一次成功的話
You can avoid future appearances of this warning by setting the value of the 'store-plaintext-passwords' option to either 'yes' or 'no' in '/home/tim/.subversion/servers'. ----------------------------------------------------------------------- Store password unencrypted (yes/no)?
# Subversion caches auth credentials by default (both username and password)
# --no-auth-cache
# configure file
# store-passwords = no
~/.subversion$ ls
auth/ <--- 保存了不同的 login
config
README.txt
servers
# /etc/subversion/servers
# /etc/subversion/config
# /etc/subversion/hairstyles
svn add filename
svn rm filename
svn move foo bar
svn mkdir blort
svn status
# svn: warning: '.' is not a working copy
# Defalult 是當前目錄
root@ubuntu:/root/testsvn# svn status
M file1
--show-updates (-u) option, which contacts the repository
co: checkout
copy all "working" files and directories to local
Usage:
svn co -r <version> url file-name
Example:
svn co http://SERVER/svn/PROJECT
svn co http://google-authenticator-apache-module.googlecode.com/svn/trunk
A trunk/base32.c A trunk/sha1.h A trunk/googleauth.conf A trunk/base32.h A trunk/httpd.conf A trunk/hmac.c A trunk/login.cgi A trunk/test.gaconf A trunk/mod_authn_google.c A trunk/README A trunk/sha1.c A trunk/Makefile A trunk/hmac.h Checked out revision 22.
ci: commit
Update to Server
usage1: update msg
svn ci -m "update msg"
usage2: 更 1 差不多, 不過 msg 由 log_msg_file 提供
svn ci -F log_msg_file
output
Sending file1 Transmitting file data . Committed revision 2.
svn cat filename # 某 file 內容
svn blame -r RevisionNumber filename # 某 version 資料
# removing working copy locks in the process.
svn cleanup
# 使用
up: update (Update your working copy)
U: File was updated
G: Automatically merged with no conflicts.
C: Not merged due to conflicts.
A: scheduled for addition
D: scheduled for deletion
M: has local modifications
svn status
svn log FILE
# 比較
svn diff FILE
# no options = will compare your working files to the cached “pristine” copies in the .svn area:
# find out exactly how you've modified
svn diff -r 123:120 FILE
svn diff -r 2:3 rules.txt
-c [--change] ARG (like -r ARG-1:ARG)
--new ARG use ARG as the newer target
# Undo your local changes
svn revert File...
# 一定要有 File
# 用 . 來做 File 是唔得的
# -R [--recursive]
svn revert -R .
svn list [TARGET[@REV]...]
--verbose (-v)
svn export http://SERVER/svn/repos1 -r 1729
# no .svn directories
svn status
# 有不存在的東西時會有 "?"
? testdir
second column shows the working-revision of the item
The third and show the revision in which the item last changed
fourth columns who changed it.
P.S.
The commands svn status, svn diff, and svn revert can be used without any network access even if your repository is across the network.
( keeping private caches )
.svn directory <-- administrative area
to add:
svn status | grep "^\?" | sed -e 's/? *//' | sed -e 's/ /\\ /g' | xargs svn add
to remove:
svn status | grep "^\!" | sed -e 's/! *//' | sed -e 's/ /\\ /g' | xargs svn remove
works fine for me.
Under Windows, the following batch file would work:
for /f "tokens=2*" %%i in ('svn status %1 ^| find "?"') do svn add "%%i"
for /f "tokens=2*" %%i in ('svn status %1 ^| find "!"') do svn delete "%%i"
svn commit -m "Automatic commit" %1
If renames or other rearrangements happen outside of Subversion, then the UI has been violated and the working copy might be broken. The client cannot guess what happened.
http://subversion.apache.org/faq.html
SVNAutoversioning
This will allow users to mount the repository as a network disk, and any changes made to the volume cause automatic commits on the server.
http://svnbook.red-bean.com/en/1.5/svn.webdav.autoversioning.html
svnadmin
svnadmin command /path/to/repos [options] [args]
Available subcommands:
crashtest
create
deltify
dump
help (?, h)
hotcopy
list-dblogs
list-unused-dblogs
load
lslocks
lstxns
pack
recover
rmlocks
rmtxns
setlog
setrevprop
setuuid
upgrade
verify
Move Directory
svnadmin dump /home/user/svn > /tmp/mydumpfile.db
svnadmin create -fs-type fsfs /home/user/newsvn
svnadmin load /home/user/newsvn/ < /tmp/dumpfile.db
svnlook
svnlook SUBCOMMAND REPOS_PATH [ARGS & OPTIONS ...]
svnlook help
Available subcommands:
author
cat
changed
date
diff
dirs-changed
help (?, h)
history
info
lock
log
propget (pget, pg)
proplist (plist, pl)
tree
uuid
youngest
svnlook info /var/svn/testsvn/
tester3 <--- author
2013-01-29 01:04:28 +0800 (Tue, 29 Jan 2013) <--- data
10
add a line <--- log
root@ubuntu:/var/svn# svnlook changed /var/svn/testsvn/
U test9.txt
svnlook youngest /var/svn/testsvn/
11
svnlook tree /var/svn/testsvn/
/
test on 1639.txt
file1
file2
file3
test by tim.txt
新增筆記本文件.jnt
test9.txt
websvn
PHP
dpkg-reconfigure websvn
svnlook
read-write access to the repository
websvn:
/etc/websvn/config.php
/etc/websvn/apache.conf
/etc/websvn/wsvn.php
$config->parentPath('/var/svn/repos');
$config->useAuthenticationFile('/var/svn/conf/authz');
# config.php
<?php
if ( file_exists("/etc/websvn/svn_deb_conf.inc") ) {
include("/etc/websvn/svn_deb_conf.inc");
}
?>
# svn_deb_conf.inc
<?php
// please edit /etc/websvn/config.php
// or use dpkg-reconfigure websvn
$config->parentPath("/var/svn");
$config->addRepository("repos 1", "file:///var/svn");
$config->setEnscriptPath("/usr/bin");
$config->setSedPath("/bin");
$config->useEnscript();
?>
uncomment $config->allowDownload(); to allow on-demand tarball generation and download from your repositories.
Features
=======
Supports multiple repositories, local or remote
Group
[groups] administrators = admin developer_team = account1, account2 [/] # no access to everyone else (*) * = @administrators = rw [repos1:/] @developer_team = rw [repos2:/] @developer_team = rw # 預設拒絕所有人進入瀏覽 [/] * =