22.1 代碼管理平臺介紹

22.1 代碼管理平臺介紹

版本控制,記錄若干文件內容變化,以便未來查閱特定版本修訂狀況
版本管理工具發展簡史,cvs svn  git 參考http://luckypoem14.github.io/test/2012/04/24/scm-history/
svn全稱subversion,是一個開源版本控制系統,始於2000年
git是linux創始人linus發起的,2005年發佈,最初目的是更好管理linux內核代碼
git和svn不一樣在於git不須要依賴服務端就能夠工做,即git是分佈式的
關於git和svn的比較你們參考http://blog.lishiming.net/?p=305
github是基於git的在線web頁面代碼託管平臺,能夠選擇付費服務
gitlab能夠認爲是一個開源的github,二者沒有直接關係html

簡單來講:
git 是一種版本控制系統,是一個命令,是一種工具
gitlib 是用於實現git功能的開發庫
github 是一個基於git實現的在線代碼倉庫,包含一個網站界面,向互聯網開放
gitlab 是一個基於git實現的在線代碼倉庫軟件,你能夠用gitlab本身搭建一個相似於github同樣的系統,通常用於在企業、學校等內部網絡搭建git私服linux

22.2 安裝svn

yum install -y subversion
 建立版本庫 
 mkdir -p /data/svnroot/myproject
 svnadmin create /data/svnroot/myproject
 cd !$/conf #authz爲權限配置文件,passwd爲密碼文件
 vim authz//配置文件改成以下
[groups]
admins = aming,user1
[/]
@admins = rw
*= r
[myproject:/]
user1 = rw
 vim passwd//加入以下內容
[users]
aming = aming_!(*$123
user1 = user1_^^^123
user2 = user2-***123
 vim svnserver.conf//更改或增長以下內容
[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
realm = /data/svnroot/myproject
svnserve -d -r /data/svnroot //這樣就啓動了
[root@Dasoncheng ~]# yum install -y subversion
[root@Dasoncheng ~]# mkdir -p /data/svnroot/project1  ##建立文件夾
[root@Dasoncheng ~]# svnadmin create /data/svnroot/project1  
##初始化文件夾,裏面會生成配置文件;(我試着沒有建立文件夾 直接初始化自動生成了文件夾)
[root@Dasoncheng ~]# ll !$
ll /data/svnroot/project1
total 8
drwxr-xr-x 2 root root  54 Oct 23 20:46 conf
drwxr-sr-x 6 root root 233 Oct 23 20:46 db
-r--r--r-- 1 root root   2 Oct 23 20:46 format
drwxr-xr-x 2 root root 231 Oct 23 20:46 hooks
drwxr-xr-x 2 root root  41 Oct 23 20:46 locks
-rw-r--r-- 1 root root 229 Oct 23 20:46 README.txt
[root@Dasoncheng ~]# cd !$/conf
cd /data/svnroot/project1/conf
[root@Dasoncheng conf]# ll  ##咱們須要對conf文件夾裏面進行修改
total 12
-rw-r--r-- 1 root root 1080 Oct 23 20:46 authz   ##這個是權限配置文件;
-rw-r--r-- 1 root root  309 Oct 23 20:46 passwd  ##這個是密碼文件;
-rw-r--r-- 1 root root 3090 Oct 23 20:46 svnserve.conf  ##這個是服務啓動的配置文件;
[root@Dasoncheng conf]# vim authz
[groups]  ##組=成員1,成員2
admins = aming,user1
[/]  ##這個"/"表明/data/svnroot/project1 這個文件夾;下面就是對其權限控制
@admins = rw  ##admins組成員 具備讀寫權限;
* = r  ##非admins具備讀權限;
[project1:/]  ##這個"[nameofproject:/]"表明的是項目名,針對不一樣項目的權限控制;
user1 = rw  ##use1對項目project1具備讀寫權限;
[root@Dasoncheng conf]# vim passwd  ##密碼配置文件;
[users]
aming = p@ssw0rd  ##格式:username = password
user1 = p@ssw0rd1
[root@Dasoncheng conf]# vim svnserve.conf
[general]
anon-access = none   ##表明未受權用戶,無任何權限
auth-access = write  ##受權用戶 可寫權限;
password-db = passwd  ##用戶密碼文件;
authz-db = authz  ##權限控制文件;
realm = /data/svnroot/myproject  ##表示對哪一個項目生效;
[root@Dasoncheng conf]# svnserve -d -r /data/svnroot/  ##-d以deamon後臺啓動,-r指svn目錄;
[root@Dasoncheng conf]# ps aux |grep svn
root       4447  0.0  0.0 162204   652 ?        Ss   21:06   0:00 svnserve -d -r /data/svnroot/
root       4449  0.0  0.0 112664   968 pts/1    S+   21:06   0:00 grep --color=auto svn
[root@Dasoncheng conf]# netstat -lntp 
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:3690            0.0.0.0:*               LISTEN      4447/svnserve

22.3 客戶端上使用svn(linux)

yum install -y  subversion
 svn checkout svn://192.168.133.130/myproject --username=aming
 cd myproject ; ls -la
 cp /etc/fstab .
 svn add .  //添加到版本控制中心
 svn commit -m 「add file」 //把文件上傳到服務器
 svn delete filename  //在本地刪除
 svn commit -m 「delete filename」 //在服務器上刪除
 svn update //把當前目錄下的文件都更新到最新版
 svn log //查看變動日誌

安裝好了,那麼 咱們用60.12用戶aming來作測試(上傳):git

[root@localhost ~]# cd /home/
[root@localhost home]# mkdir svntest  ##建立文件夾給svn用;
[root@localhost home]# cd svntest/
[root@localhost svntest]# yum install -y subversion
[root@localhost svntest]# svn checkout svn://192.168.60.11/project1 --username=aming  
##svn檢出項目project1,使用aming登陸;
Authentication realm: <svn://192.168.60.11:3690> /data/svnroot/project1
Password for 'aming':   ##輸入aming密碼;

-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:  
##警告:你的密碼對於驗證域來講
   <svn://192.168.60.11:3690> /data/svnroot/project1

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 svntest]# ll  
total 0
drwxr-xr-x 3 root root 18 Oct 23 21:45 project1
[root@localhost svntest]# cd project1/
[root@localhost project1]# ls -la
total 0
drwxr-xr-x 3 root root 18 Oct 23 21:45 .
drwxr-xr-x 3 root root 22 Oct 23 21:45 ..
drwxr-xr-x 4 root root 75 Oct 23 21:45 .svn
[root@localhost project1]# cp /etc/fstab .  ##拷貝fstab文件到當前目錄下;
[root@localhost project1]# ll
total 4
-rw-r--r-- 1 root root 501 Oct 23 21:46 fstab
[root@localhost project1]# svn add ./fstab    ##添加fstab到版本控制中心;
A         fstab
[root@localhost project1]# svn commit -m "add fstab"  ##上傳文件到服務器;
Adding         fstab
Transmitting file data .
Committed revision 1.

換60.11機器,使用user1登陸 同步svn:github

[root@Dasoncheng ~]# cd /home/
[root@Dasoncheng home]# mkdir svntest
[root@Dasoncheng home]# cd svntest/
[root@Dasoncheng svntest]# svn checkout svn://192.168.60.11/project1 --username=user1
Store password unencrypted (yes/no)? yes
A    project1/fstab
Checked out revision 1.
[root@Dasoncheng svntest]# ll
total 0
drwxr-xr-x 3 root root 31 Oct 23 21:58 project1
[root@Dasoncheng svntest]# cd project1/
[root@Dasoncheng project1]# ll
total 4
-rw-r--r-- 1 root root 501 Oct 23 21:58 fstab
[root@Dasoncheng project1]# svn delete fstab 
D         fstab
[root@Dasoncheng project1]# svn commit -m "delete fstab"
Deleting       fstab

Committed revision 2.
##60.12同步後查看
[root@localhost project1]# svn update
Updating '.':
D    fstab
Updated to revision 2.
[root@localhost project1]# ll  ##文件已經刪除;
total 0
[root@localhost project1]# svn log
------------------------------------------------------------------------
r2 | user1 | 2017-10-23 22:06:17 +0800 (Mon, 23 Oct 2017) | 1 line

delete fstab
------------------------------------------------------------------------
r1 | aming | 2017-10-23 21:47:26 +0800 (Mon, 23 Oct 2017) | 1 line

add fstab
------------------------------------------------------------------------
##接下來是作更新(同步編輯的文件):
[root@localhost project1]# vim 1.txt
[root@localhost project1]# svn add 1.txt 
A         1.txt
[root@localhost project1]# svn commit -m "add 1.txt"
Adding         1.txt
Transmitting file data .
Committed revision 3.
[root@localhost project1]# echo 'hello world' >> 1.txt
[root@localhost project1]# svn commit -m "ch 1.txt"  ##這個就是更新1.txt文件
[root@localhost project1]# svn update  ##同步服務器文件;
Updating '.':
At revision 4.
[root@localhost project1]# svn log  ##查看日誌;
------------------------------------------------------------------------
r4 | aming | 2017-10-23 22:09:40 +0800 (Mon, 23 Oct 2017) | 1 line

ch 1.txt
------------------------------------------------------------------------
r3 | aming | 2017-10-23 22:08:08 +0800 (Mon, 23 Oct 2017) | 1 line

add 1.txt
------------------------------------------------------------------------
r2 | user1 | 2017-10-23 22:06:17 +0800 (Mon, 23 Oct 2017) | 1 line

delete fstab
------------------------------------------------------------------------
r1 | aming | 2017-10-23 21:47:26 +0800 (Mon, 23 Oct 2017) | 1 line

add fstab
------------------------------------------------------------------------

聊聊:關於未加密保存密碼的文件!web

[root@localhost svn.simple]# cd /root/.subversion/auth/svn.simple
[root@localhost svn.simple]# ll
total 4
-rw-r--r-- 1 root root 153 Oct 23 21:45 5e6bd6c8885f754dad23a6cb50fc2792
[root@localhost svn.simple]# cat 5e6bd6c8885f754dad23a6cb50fc2792 
K 8
passtype
V 6
simple
K 8
password
V 8
p@ssw0rd
K 15
svn:realmstring
V 49
<svn://192.168.60.11:3690> /data/svnroot/project1
K 8
username
V 5
aming
END
##這裏面就保存了用戶名和密碼;

咱們刪掉這個文件試試:vim

[root@localhost svn.simple]# rm -f 5e6bd6c8885f754dad23a6cb50fc2792 
[root@localhost svn.simple]# cd /home/svntest/project1
[root@localhost project1]# svn update  ##同步的時候;
Updating '.':
Authentication realm: <svn://192.168.60.11:3690> /data/svnroot/project1
Password for 'root':   ##這裏提示輸入root密碼,這確定是不行的啥 咱們回車
Authentication realm: <svn://192.168.60.11:3690> /data/svnroot/project1
Username: aming  ##輸入用戶名 ok 再密碼;
Password for 'aming': 

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

   <svn://192.168.60.11:3690> /data/svnroot/project1

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
At revision 5.

22.4 客戶端上使用svn(windows)

安裝過程略過:
mark
建立文件夾提供svn服務; mark
右鍵,checkout(會彈出用戶名密碼界面輸入);
mark
驗證完成以後,就是這個界面!
mark
能夠看到,已經和服務器同步了;
建立文件,並同步:
mark
mark
mark
mark
mark 提交完成以後,咱們去其餘客戶端同步看看;windows

[root@Dasoncheng ~]# cd /home/svntest/
[root@Dasoncheng svntest]# cd project1/
[root@Dasoncheng project1]# ll
total 4
-rw-r--r-- 1 root root 70 Oct 23 22:10 1.txt
[root@Dasoncheng project1]# svn update
Updating '.':
A    2.txt
Updated to revision 6.
[root@Dasoncheng project1]# ll
total 8
-rw-r--r-- 1 root root 70 Oct 23 22:10 1.txt
-rw-r--r-- 1 root root 41 Oct 24 08:37 2.txt
[root@Dasoncheng project1]# cat 2.txt 
aaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbb[root@Dasoncheng project1]#

刪除1.txt,Windows同步查看:服務器

[root@Dasoncheng project1]# svn delete 1.txt 
D         1.txt
[root@Dasoncheng project1]# svn commit -m "delete 1.txt"
Deleting       1.txt

Committed revision 7.

mark
mark

相關文章
相關標籤/搜索