svn版本控制


Windows系統安裝svn

1、svn下載

https://sourceforge.net/projects/win32svn/

2、驗證是否安裝成功

	C:\Users\libingshen>svn --version

3、創建版本庫

	D:\mytest\mysvn\OA>svnadmin create D:\mytest\mysvn\OA

4、啟動svn服務

5、驗證svn服務是否啟動

svn服務監聽3690端口

6、svn注冊為Windows服務

tip:等號左邊沒有空格,等號右邊有一個空格。

	C:\WINDOWS\system32>sc create MySVNService binpath= "C:\Pmyprogram\svn\bin\svnserve.exe --service -r D:\mytest\mysvn" start= auto depend= Tcpip

原因:每次啟動svn服務時必須啟動一個cmd窗口,cmd窗口一關閉,svn服務就關閉。

非管理員運行時會失敗。

管理員運行


啟動、停止、刪除svn服務(管理員身份運行cmd)

	//啟動svn服務
	C:\WINDOWS\system32>sc start MySVNService

	//停止服務
	C:\WINDOWS\system32>sc stop MySVNService

	//刪除服務
	C:\WINDOWS\system32>sc delete MySVNService


7、檢出項目

	D:\mytest\mycheckout>svn checkout svn://localhost/OA MyOA

8、提交文件

--開啟匿名權限訪問

--先將文件加入版本庫,然后提交(需添加提交日志信息,不然報錯)

svn commit 命令最后可以不指定具體文件,此時表示提交當前工作副本中
的所有修改

9、更新

另一個客戶端檢出項目、更新並提交文件

	//遠程版本庫具體位置  svn://localhost/OA
	//將OA檢出到本地的目錄 MyOA2
	D:\mytest\mycheckout>svn checkout svn://localhost/OA MyOA2

10、授權訪問版本庫

--單版本庫開啟授權訪問

--多版本庫開啟授權訪問

	在版本庫根目錄 D:\mytest\mysvn 下創建 commConf 目錄
	將未修改的 authz 和 passwd 文件拷貝到 commConf 目錄下
	修改需要設置權限的版本庫的 svnserve.conf 文件
	①password-db = ../../commConf/passwd
	②authz-db = ../../commConf/authz

passwd:設置訪問版本庫的用戶信息

authz:設置用戶訪問版本庫的權限


centos7系統安裝svn

安裝服務端程序

yum install -y subversion

創建並配置版本庫

創建版本庫目錄

用該目錄來管理多個項目

mkdir -p /opt/module/svn/repository

在版本庫目錄下創建具體項目目錄

[root@izm5eac6bnsz8uq175jkvez repository]# pwd
/opt/module/svn/repository
[root@izm5eac6bnsz8uq175jkvez repository]# ll
total 4
drwxr-xr-x 6 root root 4096 Oct 20 21:15 pro_oa
[root@izm5eac6bnsz8uq175jkvez repository]# mkdir pro_oa

創建 SVN 版本庫

svnadmin create /opt/module/svn/repository/pro_oa

版本庫內容

[root@izm5eac6bnsz8uq175jkvez pro_oa]# ll
total 24
drwxr-xr-x 2 root root 4096 Oct 20 22:31 conf
drwxr-sr-x 6 root root 4096 Oct 20 22:47 db
-r--r--r-- 1 root root    2 Oct 20 21:15 format
drwxr-xr-x 2 root root 4096 Oct 20 21:15 hooks
drwxr-xr-x 2 root root 4096 Oct 20 21:15 locks
-rw-r--r-- 1 root root  229 Oct 20 21:15 README.txt

配置svn對應的服務

設置svn服務開機自啟

[root@izm5eac6bnsz8uq175jkvez pro_oa]#  systemctl enable svnserve.service

修改svn服務開機自啟默認的版本庫目錄

查看svn服務啟動的配置文件路徑/etc/sysconfig/svnserve

[root@izm5eac6bnsz8uq175jkvez pro_oa]# cat /usr/lib/systemd/system/svnserve.service
[Unit]
Description=Subversion protocol daemon
After=syslog.target network.target

[Service]
Type=forking
EnvironmentFile=/etc/sysconfig/svnserve
ExecStart=/usr/bin/svnserve  --daemon --pid-file=/run/svnserve/svnserve.pid $OPTIONS

[Install]
WantedBy=multi-user.target
[root@izm5eac6bnsz8uq175jkvez pro_oa]# 

修改svn服務啟動的配置文件,版本庫目錄OPTIONS="-r /opt/module/svn/repository"

[root@izm5eac6bnsz8uq175jkvez pro_oa]# cat /etc/sysconfig/svnserve
# OPTIONS is used to pass command-line arguments to svnserve.
# 
# Specify the repository location in -r parameter:
OPTIONS="-r /opt/module/svn/repository"
[root@izm5eac6bnsz8uq175jkvez pro_oa]# 


啟動svn服務

[root@izm5eac6bnsz8uq175jkvez pro_oa]# systemctl start svnserve.service

查看服務當前狀態

[root@izm5eac6bnsz8uq175jkvez pro_oa]# systemctl status svnserve.service
● svnserve.service - Subversion protocol daemon
   Loaded: loaded (/usr/lib/systemd/system/svnserve.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2019-10-20 21:58:58 CST; 11h ago
  Process: 778 ExecStart=/usr/bin/svnserve --daemon --pid-file=/run/svnserve/svnserve.pid $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 843 (svnserve)
   CGroup: /system.slice/svnserve.service
           └─843 /usr/bin/svnserve --daemon --pid-file=/run/svnserve/svnserve.pid -r /opt/module/svn/repository

Oct 20 21:58:58 izm5eac6bnsz8uq175jkvez systemd[1]: Starting Subversion protocol daemon...
Oct 20 21:58:58 izm5eac6bnsz8uq175jkvez systemd[1]: Started Subversion protocol daemon.
[root@izm5eac6bnsz8uq175jkvez pro_oa]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      1223/nginx: master  
tcp        0      0 0.0.0.0:8000            0.0.0.0:*               LISTEN      1223/nginx: master  
tcp        0      0 0.0.0.0:3690            0.0.0.0:*               LISTEN      843/svnserve        
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1223/nginx: master  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      991/sshd            
tcp6       0      0 :::8000                 :::*                    LISTEN      1223/nginx: master  
[root@izm5eac6bnsz8uq175jkvez pro_oa]# ps -ef|grep svn
root       843     1  0 Oct20 ?        00:00:00 /usr/bin/svnserve --daemon --pid-file=/run/svnserve/svnserve.pid -r /opt/module/svn/repository
root      2107  2029  0 09:31 pts/0    00:00:00 grep --color=auto svn


檢出項目

開發人員1號,檢出項目

[root@izm5eac6bnsz8uq175jkvez harry]# mkdir -p /root/workspace/harry
[root@izm5eac6bnsz8uq175jkvez harry]# pwd
/root/workspace/harry
[root@izm5eac6bnsz8uq175jkvez harry]# svn checkout svn://192.168.1.101/pro_oa ./

開發人員2號,檢出項目

[root@izm5eac6bnsz8uq175jkvez harry]# mkdir -p /root/workspace/sally
[root@izm5eac6bnsz8uq175jkvez sally]# pwd
/root/workspace/sally
[root@izm5eac6bnsz8uq175jkvez sally]# svn checkout svn://192.168.1.101/pro_oa ./

授權訪問

進入到項目svn版本庫,查看授權訪問的幾個相關文件

[root@izm5eac6bnsz8uq175jkvez conf]# pwd
/opt/module/svn/repository/pro_oa/conf
[root@izm5eac6bnsz8uq175jkvez conf]# ll
total 16
-rw-r--r-- 1 root root 1080 Oct 20 21:15 authz
-rw-r--r-- 1 root root  309 Oct 20 21:15 passwd
-rw-r--r-- 1 root root 3089 Oct 20 22:31 svnserve.conf
-rw-r--r-- 1 root root 3090 Oct 20 22:28 svnserve.conf.20191020
[root@izm5eac6bnsz8uq175jkvez conf]# 

匿名訪問

修改svnserve.conf文件

[root@izm5eac6bnsz8uq175jkvez conf]# ll
total 16
-rw-r--r-- 1 root root 1080 Oct 20 21:15 authz
-rw-r--r-- 1 root root  309 Oct 20 21:15 passwd
-rw-r--r-- 1 root root 3089 Oct 20 22:31 svnserve.conf
-rw-r--r-- 1 root root 3090 Oct 20 22:28 svnserve.conf.20191020
[root@izm5eac6bnsz8uq175jkvez conf]# vim svnserve.conf

anon-access = write
# auth-access = write
# password-db = passwd
# authz-db = authz

授權訪問

修改svnserve.conf文件,取消以下注釋,左邊不留空格

anon-access = none
auth-access = write
password-db = passwd
authz-db = authz

修改passwd文件,配置用戶名、密碼

[users]
# harry = harryssecret
# sally = sallyssecret
ctp = ctp
zqc = zqc
ywc = ywc
slb=slb

修改authz文件,開啟項目授權

[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
admin = ctp,zqc,ywc,slb
# [/foo/bar]
# harry = rw
# &joe = r
# * =
[pro_oa:/]
@admin = rw
# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r

文件沖突表現

不同開發人員操作同一文件

開發人員1號Harry修改hello.txt,修改后並提交

[root@izm5eac6bnsz8uq175jkvez harry]# svn update
Updating '.':
At revision 3.
[root@izm5eac6bnsz8uq175jkvez harry]# vim hello.txt 
[root@izm5eac6bnsz8uq175jkvez harry]# svn commit -m "conflict one commit"
Sending        hello.txt
Transmitting file data .
Committed revision 4.
[root@izm5eac6bnsz8uq175jkvez harry]# cat hello.txt 
sally
harray add 
sally add two
harry add one conflict commit
[root@izm5eac6bnsz8uq175jkvez harry]# 

開發人員2號Sally也修改hello.txt,修改后並提交,提示已過期,執行svn update,提示產生沖突,輸入p表示延遲解決該問題

[root@izm5eac6bnsz8uq175jkvez sally]# ll
total 4
-rw-r--r-- 1 root root 32 Oct 20 22:53 hello.txt
[root@izm5eac6bnsz8uq175jkvez sally]# svn update
Updating '.':
At revision 3.
[root@izm5eac6bnsz8uq175jkvez sally]# vim hello.txt 
[root@izm5eac6bnsz8uq175jkvez sally]# svn -m "conflict two commit"
Subcommand argument required
Type 'svn help' for usage.
[root@izm5eac6bnsz8uq175jkvez sally]# svn commit -m "conflict two commit"
Sending        hello.txt
Transmitting file data .svn: E160028: Commit failed (details follow):
svn: E160028: File '/hello.txt' is out of date
[root@izm5eac6bnsz8uq175jkvez sally]# ll
total 4
-rw-r--r-- 1 root root 62 Oct 21 10:08 hello.txt
[root@izm5eac6bnsz8uq175jkvez sally]# svn update
Updating '.':
Conflict discovered in '/root/workspace/sally/hello.txt'.
Select: (p) postpone, (df) diff-full, (e) edit,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options: p
C    hello.txt
Updated to revision 4.
Summary of conflicts:
  Text conflicts: 1
[root@izm5eac6bnsz8uq175jkvez sally]# 


此時發現多了幾個文件,hello.txt合並后的沖突文件,hello.txt.mine開發人員2號的修改文件,hello.txt.r3 服務器上的版本文件,hello.txt.r4開發人員1號的修改文件

[root@izm5eac6bnsz8uq175jkvez sally]# ll
total 16
-rw-r--r-- 1 root root 126 Oct 21 10:09 hello.txt
-rw-r--r-- 1 root root  62 Oct 21 10:09 hello.txt.mine
-rw-r--r-- 1 root root  32 Oct 21 10:09 hello.txt.r3
-rw-r--r-- 1 root root  62 Oct 21 10:09 hello.txt.r4
[root@izm5eac6bnsz8uq175jkvez sally]# cat hello.txt
sally
harray add 
sally add two
<<<<<<< .mine
sally add two conflict commit
=======
harry add one conflict commit
>>>>>>> .r4
[root@izm5eac6bnsz8uq175jkvez sally]# cat hello.txt.mine 
sally
harray add 
sally add two
sally add two conflict commit
[root@izm5eac6bnsz8uq175jkvez sally]# cat hello.txt.r3 
sally
harray add 
sally add two
[root@izm5eac6bnsz8uq175jkvez sally]# cat hello.txt.r4
sally
harray add 
sally add two
harry add one conflict commit
[root@izm5eac6bnsz8uq175jkvez sally]# 

解決

刪除多余的文件hello.txt.mine ,hello.txt.r3,hello.txt.r4,修改合並后的沖突文件hello.txt直到滿意為止

[root@izm5eac6bnsz8uq175jkvez sally]# ll
total 16
-rw-r--r-- 1 root root 126 Oct 21 10:09 hello.txt
-rw-r--r-- 1 root root  62 Oct 21 10:09 hello.txt.mine
-rw-r--r-- 1 root root  32 Oct 21 10:09 hello.txt.r3
-rw-r--r-- 1 root root  62 Oct 21 10:09 hello.txt.r4
[root@izm5eac6bnsz8uq175jkvez sally]# rm hello.txt.*
rm: remove regular file ‘hello.txt.mine’? y
rm: remove regular file ‘hello.txt.r3’? y
rm: remove regular file ‘hello.txt.r4’? y
[root@izm5eac6bnsz8uq175jkvez sally]# ll
total 4
-rw-r--r-- 1 root root 126 Oct 21 10:09 hello.txt
[root@izm5eac6bnsz8uq175jkvez sally]# cat hello.txt 
sally
harray add 
sally add two
<<<<<<< .mine
sally add two conflict commit
=======
harry add one conflict commit
>>>>>>> .r4
[root@izm5eac6bnsz8uq175jkvez sally]# vim hello.txt 
[root@izm5eac6bnsz8uq175jkvez sally]# cat hello.txt 
sally
harray add 
sally add two
sally add two conflict commit
harry add one conflict commit
[root@izm5eac6bnsz8uq175jkvez sally]# svn commit -m 'sally have solve conflict' hello.txt 
Sending        hello.txt
Transmitting file data .
Committed revision 5.
[root@izm5eac6bnsz8uq175jkvez sally]# 

eclipse使用svn

安裝svn插件

安裝subversive

1571640573650

安裝SVN Connector

1571640730501

查看svn狀態圖標

1571640787851

svn默認用戶名和密碼保存位置

C:\Users\shenlibing\AppData\Roaming\Subversion\auth\svn.simple

如果使用eclipse的話,連接資源庫的時候選擇記住用戶名和密碼,還會在以下路徑存一份用戶名和密碼的信息

C:\Users\shenlibing\.eclipse\org.eclipse.equinox.security

1571651691763

因此需要刪除如上兩處位置的內容,然后重啟eclipse

添加忽略文件

項目--->右鍵--->Team--->Set Properties

1571641088731

修改添加的忽略文件

項目--->右鍵--->Team--->Show Properties

1571641196480

全局添加忽略文件

進入到以下目錄,修改config文件

C:\Users\shenlibing\AppData\Roaming\Subversion

開啟全局忽略文件注釋

global-ignores = *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo __pycache__ *.rej *~ #*# .#* .*.swp .DS_Store *.iml .idea */.idea/* .classpath .settings */.settings/* .project target */target/*

開啟后eclipse需要重啟,如果是eclipseidea的話,target目錄會自動忽略

分享上傳項目

File--->New--->Project,新建maven項目

1571643038930

使用骨架

1571643112714

1571643162859

提示缺少web.xml文件

1571643232573

解決

項目--->右鍵--->Java EE Tools--->Generate Deployment Descriptor Stub

項目--->右鍵--->Team--->Share Project,上傳項目

選擇版本工具svn

1571643500959

選擇一個已經存在的資源庫位置

1571643561780

確認工程根目錄下子目錄和文件是否全部上傳,先別上傳

1571643848217

添加忽略上傳的文件,觀察圖標前后變化

1571644168459

1571644138612

上傳

檢出項目

File--->import

1571642181335

檢出項目使用已經存在的倉庫地址

1571642221764

找到我們的項目

1571642340569

使檢出的目錄本身作為工程

1571642436006

轉換工程類型,項目--->右鍵--->Configure--->Convert to Maven Project

1571642879907

1571642899592

IDEA使用svn

必須安裝烏龜TortoiseSVN,因為idea是使用烏龜的svn命令進行分享和檢出的

下載安裝64位的小烏龜

idea使用烏龜

1571673558827

檢出項目

1571673644771

輸入url地址

1571673720591

添加全局忽略文件,通過小烏龜進行操作,任意目錄,右鍵--->找到小烏龜--->Settings,開啟全局注釋

1571673850072

global-ignores = *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo __pycache__ *.rej *~ #*# .#* .*.swp .DS_Store *.iml .idea */.idea/* .classpath .settings */.settings/* .project target */target/*

注意:idea不管是使用svn還是Git都是需要安裝客戶端工具的,比如小烏龜,通過客戶端工具操作遠程的svn版本庫或者Git的版本庫,這一點和eclipse不太一樣,eclipse可以直接使用插件

本文由博客一文多發平台 OpenWrite 發布!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM