SVN Beginning
http://blog.doesite.net/read.php?save_215
1.安裝 subversion
# apt-get install subversion subversion-tools
創建一個新的儲存庫:
#svnadmin create /svn/repository
在/svn目錄創建一個新的空儲存庫,數據儲存方式默認采用Berkeley DB。
導入你的源碼:
# svn import /svn/repository file:///data/svn/ldap
把/data/ldap整個目錄導入到儲存庫中的repository目錄中,儲存庫的repository目錄會自動創建。
顯示儲存庫內容:
mt@mtmt:~$ svn list file:///svn/repository
.cache/
.project
.projectOptions
.settings/
bbscnmo/
newcnmo/
顯示目錄內容,成功導入。
上面使用了file:///形式的URL來訪問Subversion庫,這表示在本地通過文件系統訪問。但我們的Subversion庫可能需要通過網絡被其它用戶訪問,這就需要用到其它的協議,下表是Subversion支持的各種訪問協議:
訪問協議
協議 訪問方法
file:/// 通過本地磁盤訪問。
http:// 與Apache組合,通過WebDAV協議訪問。
https:// 同上,但支持SSL協議加密連接。
svn:// 通過svnserve服務自定義的協議訪問。
svn+ssh:// 同上,但通過SSH協議加密連接。
2.配置 subversion 與Apache組合通過WebDAV方式訪問Subversion庫
# apt-get install apache2 libapache2-svn
配置文件位于/etc/apache2/mods-enabled/目錄下,配置文件共有兩個,分別是dav_svn.conf和dav_svn.load,dav_svn.load文件負責裝載必要的模塊,內容如下:
# Load mod_dav_svn when apache starts
LoadModule dav_svn_module /usr/lib/apache2/modules/mod_dav_svn.so
LoadModule authz_svn_module /usr/lib/apache2/modules/mod_authz_svn.so
在裝載mod_dav_svn.so前,必須先裝載mod_dav.so模塊。它由dav.load文件控制,內容如下:
LoadModule dav_module /usr/lib/apache2/modules/mod_dav.so
dav_svn.conf是mod_dav_svn.so模塊的配置文件,內容如下:
# dav_svn.conf - Example Subversion/Apache configuration
#
# For details and further options see the Apache user manual and
# the Subversion book.
# …
# URL controls how the repository appears to the outside world.
# In this example clients access the repository as http://hostname/svn/
#設置訪問路徑
# Uncomment this to enable the repository,
DAV svn #啟用by siko
# Set this to the path to your repository
SVNPath /data/subversion #設置儲存庫路徑,僅支持單個儲存庫,該路徑要可被Apache進程訪問。
#SVNParentPath /data/subversion #如果subversion下有多個儲存庫,則用SVNParentPath
# The following allows for basic http authentication. Basic authentication
# should not be considered secure for any particularly rigorous definition of
# secure.
# to create a passwd file #按下面的步驟創建Apache用戶驗證文件
# # rm -f /etc/apache2/dav_svn.passwd
# # htpasswd2 -c /etc/apache2/dav_svn.passwd dwhedon
# New password:
# Re-type new password:
# Adding password for user dwhedon
# #
# Uncomment the following 3 lines to enable Basic Authentication
AuthType Basic #啟用Apache基礎驗證
AuthName “Subversion Repository” #設置驗證框標題
AuthUserFile /etc/apache2/dav_svn.passwd #指定驗證用戶文件名
# Uncomment the following line to enable Authz Authentication
AuthzSVNAccessFile /etc/apache2/dav_svn.authz #啟用目錄級別授權,dav_svn.authz是授權配置文檔
# The following three lines allow anonymous read, but make
# committers authenticate themselves.
#
#允許匿名訪問,不允許Commit,不能與AuthzSVNAccessFile同時使用
Require valid-user
#
修改/data/subversion目錄訪問權限使它可被Apache進程訪問,我的Apache是用www-data啟動的,所以設置方法如下:
# chown -R www-data.www-data /data/subversion
通 過Apache的用戶驗證功能可以區別匿名用戶和驗證用戶,從而賦予匿名用戶讀權限和驗證用戶讀/寫的權限。這些權限只能在全局范圍內設置,不能設置具體 的某個目錄是否能被某個用戶操作。要實現目錄級別的授權,就要使用mod_authz_svn.so模塊提供的 AuthzSVNAccessFile指令。它會指定一個授權文檔,該授權文檔設置具體的目錄權限。根據上面的配置,授權文檔名叫 dav_svn.authz,它的內容如下:
[groups] #定義組
admin=jims,ringkee
tests=tester1,tester2
[erp:/] #定義erp儲存庫根目錄的訪問權限
@admin=rw #admin組有讀寫權限
tests=r #test用戶只有讀權限
[oa:/test] #定義oa儲存庫下test目錄的訪問權限
*= #禁止所有用戶訪問,星號代表所有用戶,權限為空代表沒有任何權限
ringkee=rw #打開ringkee用戶的讀寫權限
在該文件中使用的用戶需在apache2的用戶文件/etc/apache2/dav_svn.passwd中預先設置好。
3.安裝trac #sudo apt-get install trac 配置TRAC
#cd /trac/
#trac-admin repository initenv
在運行trac-admin時有一步設置需要注意,就是”Path to repository”,要指向上面的/svn/repository
chown -R www-data.www-data /trac/repository
以CGI方式運行TRAC,有一些設置要做
建立密碼文件:
htpasswd -c /somewhere/trac.htpasswd username
編輯apache的apache2.conf
#edit by siko@ 2006.11.24
ScriptAlias /trac /usr/share/trac/cgi-bin/trac.cgi
SetEnv TRAC_ENV “/trac/repository”
Alias /tracdoc “/usr/share/trac/htdocs/”
Options -Indexes -MultiViews
AllowOverride None
Order allow,deny
Allow from all
AuthType Basic
AuthName “Trac”
AuthUserFile /home/mt/trac.htpasswd
Require valid-user
重啟apache使其生效
4. svn的eclipse插件 安裝配置:
1.更新安裝http://subclipse.tigris.org/update的subclipse插件
2.安裝完成后eclipse會自動重啟后,在svn的透視圖中可以看到svn的相關菜單
3.將新的 SVN 資源庫添加至“SVN 資源庫。url為http://your_ip/svn
4.引用項目成功后,便可以用前面的用戶名和密碼來更新和提交工程內文件了。
5.subclipse的較新版本都是中文的,詳細操作略。svn有很多的客戶端,在此只通過命令行來操作,結合eclipse的插件來控制版本并不涉及任何客戶端程序。