Centos下SVN環境部署記錄

 

大多數狀況下,咱們平常工做中用的版本控制系統都會選擇分佈式的Git,它相比於集中式的SVN有不少優點。可是有些項目軟件基於自身限制,可能只支持SVN作工程同步。廢話就很少說了,下面記錄下SVN的部署和使用過程:php

1)安裝SVNhtml

[root@svn-server ~]# rpm -qa subversion
[root@svn-server ~]# yum remove subversion
[root@svn-server ~]# yum -y install subversion
[root@svn-server ~]# svnversion --version
 
啓動svn,啓動時要指定svn的倉庫目錄
[root@svn-server ~]# mkdir -p /data/svn
[root@svn-server ~]# /usr/bin/svnserve -d -r /data/svn
[root@svn-server ~]# ps -ef|grep svn
root     19826     1  0 10:52 ?        00:00:00 /usr/bin/svnserve -d -r /data/svn
root     19829 19688  0 10:52 pts/1    00:00:00 grep svn
[root@svn-server ~]# lsof -i:3690                     #svn默認端口是3690
COMMAND    PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
svnserve 19826 root    3u  IPv4 12251011      0t0  TCP *:svn (LISTEN)

特別注意:
svnserver的啓動命令要使用上面的"/usr/bin/svnserve -d -r /data/svn"
不要使用"service svnserve start"命令來啓動,不然會形成svn下載時報錯:svn: No repository found in 'svn://*.*.*.*/*'

設置開機啓動
[root@svn-server ~]# echo "/usr/bin/svnserve -d -r /data/svn" >> /etc/rc.local
 
中止和重啓SVN
[root@svn-server ~]# killall svnserve
[root@svn-server ~]# ps -ef|grep svn
[root@svn-server ~]# /usr/bin/svnserve -d -r /data/svn
[root@svn-server ~]# ps -ef|grep svn
 
若是已經有svn在運行,能夠換一個端口運行
[root@svn-server ~]# /usr/bin/svnserve -d -r /data/svn --listen-port 3391
[root@svn-server ~]# lsof -i:3391
 
關閉防火牆,不然要打開3690端口
[root@svn-server ~]# /etc/init.d/iptables stop

2)代碼庫建立及配置apache

以下面建立兩個代碼庫,庫名爲kevin和grace
[root@svn-server ~]# svnadmin create /data/svn/kevin
[root@svn-server ~]# svnadmin create /data/svn/grace
[root@svn-server ~]# ls /data/svn/kevin/
conf  db  format  hooks  locks  README.txt
[root@svn-server ~]# ls /data/svn/grace/
conf  db  format  hooks  locks  README.txt

配置代碼庫,這裏以kevin代碼庫爲例進行說明
[root@svn-server ~]# cd /data/svn/kevin/conf/
[root@svn-server conf]# ll
total 12
-rw-r--r--. 1 root root 1080 May 31 10:59 authz           #權限控制文件
-rw-r--r--. 1 root root  309 May 31 10:59 passwd          #賬號密碼文件
-rw-r--r--. 1 root root 2279 May 31 10:59 svnserve.conf   #SVN服務配置文件

設置該代碼庫的登陸賬號和密碼(因爲是svn本身啓動的,沒有藉助於apache啓動,因此這裏的密碼是明文)
[root@svn-server conf]# vim passwd
......
[users]
# harry = harryssecret
# sally = sallyssecret
wangshibo = wangshibo@123
hanlili = hanlili@123
zhanghuan = zhanghuan@123
limin = limin@123

設置該代碼庫的操做權限
權限主體能夠是別名,用戶組、用戶或*;別名在前面加&;用戶組在前面加@;*表示所有用戶;
權限能夠是w、r、wr和空,空表示沒有任何權限。
[root@svn-server conf]# vim authz
.....
[aliases]         #設置別名
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average
ops = wanghsibo,hanlili

[groups]         #設置組
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
admin = wanghsibo,hanlili           #建立一個admin組,將用戶加入到組
devha = zhuanghuan,limin

# [/foo/bar]     
# harry = rw
# &joe = r
# * =

# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r

[/]         #根目錄權限設置,用戶對kevin代碼庫根目錄的讀寫權限
wangshibo = rw
hanlili = rw
@devha = r

[/haha/test]       
&ops = rw
limin = rw

[repository:/yunwei/kaixin]
* = rw

修改svnserve.conf文件(在[general]區域添加下面四行內容)
[root@svn-server conf]# vim svnserve.conf  
.....
[general]
anon-access = none           #匿名用戶可讀
auth-access = write          #受權用戶可寫 
password-db = passwd         #使用哪一個文件做爲帳號文件。因爲同在一個目錄路徑下,因此這裏不用全路徑
authz-db = authz             #使用哪一個文件做爲權限文件
realm = /data/svn/kevin      #認證命名空間,subversion會在認證提示裏顯示,而且做爲憑證緩存的關鍵字

重啓svn
[root@svn-server conf]# killall svnserve 
[root@svn-server conf]# ps -ef|grep svn
root     20137 19688  0 11:41 pts/1    00:00:00 grep svn
[root@svn-server conf]# /usr/bin/svnserve -d -r /data/svn
[root@svn-server conf]# ps -ef|grep svn
root     20139     1  0 11:41 ?        00:00:00 /usr/bin/svnserve -d -r /data/svn
root     20141 19688  0 11:41 pts/1    00:00:00 grep svn

3)SVN客戶端常規操做命令總結vim

客戶機要安裝svn,確保有svn相關操做命令
[root@localhost ~]# yum install -y subversion

=======================================================================
查看svn的相關操做命令
[root@localhost svndata]# svn --help
usage: svn <subcommand> [options] [args]
Subversion command-line client, version 1.6.11.
Type 'svn help <subcommand>' for help on a specific subcommand.
Type 'svn --version' to see the program version and RA modules
  or 'svn --version --quiet' to see just the version number.

Most subcommands take file and/or directory arguments, recursing
on the directories.  If no arguments are supplied to such a
command, it recurses on the current directory (inclusive) by default.

Available subcommands:
   add
   blame (praise, annotate, ann)
   cat
   changelist (cl)
   checkout (co)
   cleanup
   commit (ci)
   copy (cp)
   delete (del, remove, rm)
   diff (di)
   export
   help (?, h)
   import
   info
   list (ls)
   lock
   log
   merge
   mergeinfo
   mkdir
   move (mv, rename, ren)
   propdel (pdel, pd)
   propedit (pedit, pe)
   propget (pget, pg)
   proplist (plist, pl)
   propset (pset, ps)
   resolve
   resolved
   revert
   status (stat, st)
   switch (sw)
   unlock
   update (up)

Subversion is a tool for version control.
For additional information, see http://subversion.tigris.org/

=======================================================================
客戶機下載svn代碼庫文件(192.168.10.202是上面svn服務端地址。即下面kevin代碼庫)
即從版本庫中導出
[root@localhost svndata]# svn checkout svn://192.168.10.202/kevin
Authentication realm: <svn://192.168.10.202:3690> /data/svn/kevin
Password for 'root':               #首次須要輸入本機root密碼
Authentication realm: <svn://192.168.10.202:3690> /data/svn/kevin
Username: wangshibo                #輸入svn設置的用戶名,這裏選擇wangshibo
Password for 'wangshibo':          #輸入wangshibo密碼

-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:

   <svn://192.168.10.202:3690> /data/svn/kevin

can only be stored to disk unencrypted!  You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible.  See the documentation for details.

You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/root/.subversion/servers'.
-----------------------------------------------------------------------
Store password unencrypted (yes/no)? yes
Checked out revision 0.

=======================================================================
須要注意:也可使用帶用戶名和密碼的訪問(svn co 等同於svn checkout):
[root@localhost svndata]# svn co --username wangshibo --password wangshibo@123 svn://192.168.10.202/kevin

-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:

   <svn://192.168.10.202:3690> /data/svn/kevin

can only be stored to disk unencrypted!  You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible.  See the documentation for details.

You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/root/.subversion/servers'.
-----------------------------------------------------------------------
Store password unencrypted (yes/no)? yes
Checked out revision 0.

[root@localhost svndata]# ls
kevin
[root@localhost svndata]# cd kevin/
[root@localhost kevin]# ll -a
total 16
drwxr-xr-x. 3 root root 4096 May 31 14:41 .
drwxr-xr-x. 3 root root 4096 May 31 14:17 ..
drwxr-xr-x. 6 root root 4096 May 31 14:42 .svn

+++++++++++++++++++++++++++++++++
舒適提示:
svn checkout(即svn co)表示檢出。這樣下載到的svn代碼庫裏包括.svn
# svn co http://路徑(目錄或文件的全路徑) [本地目錄全路徑] --username 用戶名 --password 密碼
# svn co svn://路徑(目錄或文件的全路徑) [本地目錄全路徑] --username 用戶名 --password 密碼
# svn checkout http://路徑(目錄或文件的全路徑) [本地目錄全路徑] --username 用戶名
# svn checkout svn://路徑(目錄或文件的全路徑) [本地目錄全路徑] --username 用戶名

注意:若是不帶--password 參數傳輸密碼的話,會提示輸入密碼,建議不要用明文的--password 選項。
  其中 username 與 password前是兩個短線,不是一個。
  不指定本地目錄全路徑,則檢出到當前目錄下。
例子:
svn co svn://192.168.10.202/kevin /data/svndata --username wangshibo --password wangshibo@123
svn co http://192.168.10.202/kevin --username wangshibo --password wangshibo@123 
svn checkout svn://192.168.10.202/kevin /data/svndata --username wangshibo --password wangshibo@123
svn checkout http://192.168.10.202/kevin --username wangshibo --password wangshibo@123

=======================================================================
svn導出(導出一個乾淨的不帶.svn文件夾的目錄樹)
svn export [-r 版本號] http://路徑(目錄或文件的全路徑) [本地目錄全路徑] --username 用戶名
svn export [-r 版本號] svn://路徑(目錄或文件的全路徑) [本地目錄全路徑] --username 用戶名
svn export 本地檢出的(即帶有.svn文件夾的)目錄全路徑 要導出的本地目錄全路徑
注意:
第一種從版本庫導出乾淨工做目錄樹的形式是指定URL,若是指定了修訂版本號,會導出相應的版本,若是沒有指定修訂版本,則會導出最新的,導出到指定位置。
若是省略 本地目錄全路徑,URL的最後一部分會做爲本地目錄的名字。
第二種形式是指定 本地檢出的目錄全路徑 到 要導出的本地目錄全路徑,全部的本地修改將會保留,可是不在版本控制下(即沒提交的新文件,由於.svn文件夾
裏沒有與之相關的信息記錄)的文件不會拷貝。

例子:
注意/opt/svndata目錄不能提早建立,下面導出命令執行後會自動建立該目錄
即把kevin版本庫裏的全部文件都導出到本地的/op/svndata目錄下了,不包括.svn
[root@localhost ~]# svn export svn://192.168.10.202/kevin /opt/svndata/ --username wangshibo --password wangshibo@123
A    /opt/svndata
A    /opt/svndata/test.html
Exported revision 7.

[root@localhost ~]# ls /opt/svndata/        #如上,kevin版本庫裏尚未任何文件
[root@localhost ~]# cd /opt/svndata/
[root@localhost svndata]# ll -a             #查看,發現導出後沒有帶.svn
total 12
drwxr-xr-x. 2 root root 4096 May 31 14:52 .
drwxr-xr-x. 4 root root 4096 May 31 14:52 ..

=======================================================================
添加新文件(svn add)
注:告訴SVN服務器要添加文件了,還要用svn commint -m真實的上傳上去!
svn add test.php #添加test.php 
svn commit -m "添加個人測試用test.php" test.php  #提交新加的文件到svn服務器裏
svn add *.php #添加當前目錄下全部的php文件
svn commit -m "添加個人測試用所有php文件" *.php

[root@localhost kevin]# echo "test123123" > test.html
[root@localhost kevin]# svn add test.html 
A         test.html
[root@localhost kevin]# svn commit -m "this is test html" 
Adding         test.html
Transmitting file data .
Committed revision 1.
[root@localhost kevin]# mkdir haha
[root@localhost kevin]# svn add haha
A         haha
[root@localhost kevin]# svn commit -m "add haha"         #"svn commit"能夠簡寫成"svn ci"
Adding         haha

Committed revision 2.
[root@localhost kevin]# ls
haha  test.html

=======================================================================
svn 提交
svn commit -m "提交備註信息文本" [-N] [--no-unlock] 文件名
svn ci -m "提交備註信息文本" [-N] [--no-unlock] 文件名
必須帶上-m參數,參數能夠爲空,可是必須寫上-m

例子:
svn commit -m "提交當前目錄下的所有在版本控制下的文件" *    #注意這個*表示所有文件
svn commit -m "提交個人測試用test.php" test.php
svn commit -m "提交個人測試用test.php" -N --no-unlock test.php    #保持鎖就用–no-unlock開關
svn ci -m "提交當前目錄下的所有在版本控制下的文件" *    #注意這個*表示所有文件
svn ci -m "提交個人測試用test.php" test.php
svn ci -m "提交個人測試用test.php" -N --no-unlock test.php    #保持鎖就用–no-unlock開關

=======================================================================
svn更新操做。即把svn服務器上最新的版本更新下來
[root@localhost kevin]# svn update     或者"svn up"
At revision 1.

=======================================================================
svn查看
[root@localhost kevin]# svn info
Path: .
URL: svn://192.168.10.202/kevin
Repository Root: svn://192.168.10.202/kevin
Repository UUID: a5e3da23-8188-47af-afb7-fe4507492688
Revision: 1
Node Kind: directory
Schedule: normal
Last Changed Author: wangshibo
Last Changed Rev: 1
Last Changed Date: 2018-05-31 14:21:46 +0800 (Thu, 31 May 2018)

=======================================================================
svn刪除文件(簡寫svn del)
svn delete svn://路徑(目錄或文件的全路徑) -m "刪除備註信息文本"
推薦以下操做:
# svn delete 文件名 
# svn ci -m "刪除備註信息文本"

[root@localhost kevin]# svn delete haha             #或者svn del haha
D         haha
[root@localhost kevin]# svn commit -m "del haha"    #或者svn ci -m "del haha"
Deleting       haha

Committed revision 4.
[root@localhost kevin]# ls
test.html

[root@localhost kevin]# svn delete svn://192.168.10.202/kevin/test.html -m "刪除測試文件test.html
[root@localhost kevin]# svn update
D         haha
D         test.html
Updated to revision 8.
[root@localhost kevin]# ls
[root@localhost kevin]# 

注意:svn的刪除使用delete,而不是rm

=======================================================================
svn查看日誌
[root@localhost kevin]# svn log    #顯示全部文件的全部修改記錄
------------------------------------------------------------------------
r1 | wangshibo | 2018-05-31 14:21:46 +0800 (Thu, 31 May 2018) | 1 line

this is test html
------------------------------------------------------------------------
[root@localhost kevin]# svn log test.html     #顯示test.html這個文件的全部修改記錄,及其版本號的變化 
------------------------------------------------------------------------
r1 | wangshibo | 2018-05-31 14:21:46 +0800 (Thu, 31 May 2018) | 1 line

this is test html
------------------------------------------------------------------------

=======================================================================
版本庫下的文件和目錄列表 
[root@localhost kevin]# svn ls
test.html

=======================================================================
恢復本地修改 
svn revert: 恢復原始未改變的工做副本文件 (恢復大部份的本地修改)。
revert: 用法: revert PATH... 
注意: 本子命令不會存取網絡,而且會解除衝突的情況。可是它不會恢復被刪除的目錄;也不會恢復已經通過svn commit提交過的文件
[root@localhost kevin]# cat test.html 
test123123
[root@localhost kevin]# echo "5555" >> test.html 
[root@localhost kevin]# cat test.html 
test123123
5555
[root@localhost kevin]# svn revert test.html 
Reverted 'test.html'
[root@localhost kevin]# cat test.html 
test123123

=======================================================================
加鎖/解鎖 
svn lock -m 「加鎖備註信息文本「 [--force] 文件名 
svn unlock 文件名
例子:
# svn lock -m 「鎖信測試用test.php文件「 test.php 
# svn unlock test.php

=======================================================================
比較差別 
svn diff 文件名 
svn diff -r 修正版本號m:修正版本號n 文件名
例子:
# svn diff test.php<- 將修改的文件與基礎版本比較
# svn diff -r 200:201 test.php<- 對 修正版本號200 和 修正版本號201 比較差別

=======================================================================
查看文件或目錄狀態(簡稱svn st)
# svn st 目錄路徑/名
# svn status 目錄路徑/名   
目錄下的文件和子目錄的狀態,正常狀態不顯示 
?:不在svn的控制中; M:內容被修改;C:發生衝突;A:預約加入到版本庫;K:被鎖定

# svn -v 目錄路徑/名
# svn status -v 目錄路徑/名
顯示文件和子目錄狀態
第一列保持相同,第二列顯示工做版本號,
第三和第四列顯示最後一次修改的版本號和修改人 
注意:
svn status、svn diff和 svn revert這三條命令在沒有網絡的狀況下也能夠執行的,緣由是svn在本地的.svn中保留了本地版本的原始拷貝。
[root@localhost kevin]# svn status -v test.html 
1        1 wangshibo    test.html

=======================================================================
解決衝突 
# svn resolved [本地目錄全路徑]

例子:
# svn update
C foo.c
Updated to revision 31.

若是你在更新時獲得衝突,你的工做拷貝會產生三個新的文件:
# ls
foo.c
foo.c.mine
foo.c.r30
foo.c.r31
當你解決了foo.c的衝突,而且準備提交,運行svn resolved讓你的工做拷貝知道你已經完成了全部事情。
你能夠僅僅刪除衝突的文件而且提交,可是svn resolved除

=======================================================================
新建一個分支copy
# svn copy branchA branchB -m "make B branch" 
表示從branchA拷貝出一個新分支branchB

=======================================================================
合併內容到分支merge
# svn merge branchA branchB 
把對branchA的修改合併到分支branchB
相關文章
相關標籤/搜索