代码管理平台的常识
(1)代码管理工具发展简史
版本控制:记录若干文件内容变化,以便将来查阅特定版本修订情况。
版本管理工具发展简史,CVS→SVN→Git 。
参考http://luckypoem14.github.io/test/2012/04/24/scm-history/。
(2)svn与git的开端
SVN全称subversion,是一个开源版本控制系统,始于2000年。
Git是Linux创始人Linus发起的,2005年发布,最初目的是更好管理Linux内核代码。
(3)SVN与Git的区别
Git和SVN不同在于Git不需要依赖服务端就可以工作,即Git是分布式的。
关于Git和SVN的比较大家参考http://blog.lishiming.net/?p=305。
(4)简单了解GitLab与GitHub
GitHub是基于Git的在线Web页面代码托管平台,可以选择付费服务。
GitLab可以认为是一个开源的GitHub,两者没有直接关系。
服务端SVN的安装
1.yum源(我使用的是网络yum源)
网络配置·重启网络·ping通网络
[root@localhost ~]# vi /etc/sysconfig/network-scripts//ifcfg-eno16777728
DNS1=114.114.114.114
[root@localhost ~]# systemctl restart network
[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (36.152.44.95) 56(84) bytes of data.
64 bytes from 36.152.44.95: icmp_seq=1 ttl=128 time=75.9 ms
[root@localhost ~]# yum repolist
Loaded plugins: fastestmirror
base | 3.6 kB 00:00
extras | 2.9 kB 00:00
updates | 2.9 kB 00:00
(1/4): base/7/x86_64/group_gz | 153 kB 00:00
(2/4): extras/7/x86_64/primary_db | 225 kB 00:01
(3/4): updates/7/x86_64/primary_db | 5.6 MB 00:02
(4/4): base/7/x86_64/primary_db | 6.1 MB 00:09
Determining fastest mirrors
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.nju.edu.cn
repo id repo name status
base/7/x86_64 CentOS-7 - Base 10,072
extras/7/x86_64 CentOS-7 - Extras 453
updates/7/x86_64 CentOS-7 - Updates 1,687
repolist: 12,212
2.SVN安装:
[root@localhost ~]# yum install -y subversion
3.创建版本库
[root@localhost ~]# mkdir -p /data/svnroot/myproject
[root@localhost ~]# svnadmin create /data/svnroot/myproject
[root@localhost ~]# cd !$ //authz为权限配置文件,passwd为密码文件
cd /data/svnroot/myproject
4.修改配置文件
[root@localhost myproject]# cd conf/
[root@localhost conf]# vi authz
###This file is an example authorization file for svnserve.
###Its format is identical to that of mod_authz_svn authorization
###files.
###As shown below each section defines authorizations for the path and
###(optional) repository specified by the section name.
###The authorizations follow. An authorization line can refer to:
###- a single user,
###- a group of users defined in a special [groups] section,
###- an alias defined in a special [aliases] section,
###- all authenticated users, using the '$authenticated' token,
###- only anonymous users, using the '$anonymous' token,
###- anyone, using the '*' wildcard.
###
###A match can be inverted by prefixing the rule with '~'. Rules can
###grant read ('r') access, read-write ('rw') access, or no access
###('').
[aliases]
#joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average
[groups]
#harry_and_sally = harry,sally
#harry_sally_and_joe = harry,sally,&joe
admins = lsk,user1 //admins组包含lsk与user1用户
#[/foo/bar]
#harry = rw
#&joe = r
#* =
#[repository:/baz/fuz]
#@harry_and_sally = rw
#* = r
[/] //指项目目录
@admins = rw //设置组权限
*= r
[myproject:/] //针对项目设置权限
user1 = rw
"authz" 37L, 1145C written
[root@localhost conf]# vi passwd
###This file is an example password file for svnserve.
###Its format is similar to that of svnserve.conf. As shown in the
###example below it contains one section labelled [users].
###The name and password for each user follow, one account per line.
[users]
#harry = harryssecret
#sally = sallyssecret
lsk= lsk000 //添加如下内容
user1=user1000
user2=user2000
"passwd" 12L, 352C written
[root@localhost conf]# vi svnserve.conf
###This file controls the configuration of the svnserve daemon, if you
###use it to allow access to this repository. (If you only allow
###access through http: and/or file: URLs, then this file is
###irrelevant.)
###Visit http://subversion.apache.org/ for more information.
[general]
###The anon-access and auth-access options control access to the
###repository for unauthenticated (a.k.a. anonymous) users and
###authenticated users, respectively.
###Valid values are "write", "read", and "none".
###Setting the value to "none" prohibits both reading and writing;
###"read" allows read-only access, and "write" allows complete
###read/write access to the repository.
###The sample settings below are the defaults and specify that anonymous
###users have read-only access to the repository, while authenticated
###users have read and write access to the repository.
#anon-access = read
#auth-access = write
###The password-db option controls the location of the password
###database file. Unless you specify a path starting with a /,
###the file's location is relative to the directory containing
###this configuration file.
###If SASL is enabled (see below), this file will NOT be used.
###Uncomment the line below to use the default password file.
#password-db = passwd
###The authz-db option controls the location of the authorization
realm = /data/svnroot/myproject
###This file controls the configuration of the svnserve daemon, if you
###use it to allow access to this repository. (If you only allow
###access through http: and/or file: URLs, then this file is
###irrelevant.)
###Visit http://subversion.apache.org/ for more information.
[general] //更改或增加如下内容
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
realm = /data/svnroot/myproject
###The anon-access and auth-access options control access to the
###repository for unauthenticated (a.k.a. anonymous) users and
###authenticated users, respectively.
###Valid values are "write", "read", and "none".
###Setting the value to "none" prohibits both reading and writing;
###"read" allows read-only access, and "write" allows complete
###read/write access to the repository.
###The sample settings below are the defaults and specify that anonymous
###users have read-only access to the repository, while authenticated
###users have read and write access to the repository.
#anon-access = read
#auth-access = write
##The password-db option controls the location of the password
###database file. Unless you specify a path starting with a /,
###the file's location is relative to the directory containing
###this configuration file.
###If SASL is enabled (see below), this file will NOT be used.
###Uncomment the line below to use the default password file.
#password-db = passwd
###The authz-db option controls the location of the authorization
###rules for path-based access control. Unless you specify a path
###starting with a /, the file's location is relative to the the
###directory containing this file. If you don't specify an
"svnserve.conf" 66L, 3199C written
[root@localhost conf]# svnserve -d -r /data/svnroot //启动
5.拉取项目
[root@localhost conf]# cd /opt
[root@localhost opt]# svn checkout svn://192.168.200.23/myproject --username=lsk
Authentication realm: <svn://192.168.200.23:3690> /data/svnroot/myproject
Password for 'lsk': //输入root的密码
Authentication realm: <svn://192.168.200.23:3690> /data/svnroot/myproject
Username: lsk //输入用户名
Password for 'lsk': //输入该用户密码:lsk000
-----------------------------------------------------------------------
ATTENTION! Your password for authentication realm:
<svn://192.168.200.23:3690> /data/svnroot/myproject
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 输入yes
Checked out revision 0.
[root@localhost opt]# ls
myproject
[root@localhost opt]# cd myproject/
[root@localhost myproject]# ll -a
total 0
drwxr-xr-x. 3 root root 17 Nov 19 01:32 .
drwxr-xr-x. 3 root root 22 Nov 19 01:32 ..
drwxr-xr-x. 4 root root 70 Nov 19 01:32 .svn
客户端SVN的安装与使用
1、安装svn
[root@fengxi ~]# yum install -y subversion
[root@fengxi ~]# cd /opt
[root@fengxi opt]# rpm -qa subversion
subversion-1.7.14-10.el7.x86_64
2.关闭服务端防火墙
[root@fengxi opt]# systemctl stop firewalld
3.拉取项目
[root@fengxi myproject]# cd /opt
[root@fengxi opt]# svn checkout svn://192.168.200.23/myproject --username=lsk
Authentication realm: <svn://192.168.200.23:3690> /data/svnroot/myproject
Password for 'lsk':
Authentication realm: <svn://192.168.200.23:3690> /data/svnroot/myproject
Username: lsk
Password for 'lsk':
-----------------------------------------------------------------------
ATTENTION! Your password for authentication realm:
<svn://192.168.200.23:3690> /data/svnroot/myproject
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@fengxi opt]# cd myproject/
[root@fengxi myproject]# ls -la
total 0
drwxr-xr-x. 3 root root 17 Nov 10 02:45 .
drwxr-xr-x. 4 root root 34 Nov 10 02:45 ..
drwxr-xr-x. 4 root root 70 Nov 10 02:45 .svn
4.复制到当前目录及添加到版本控制中心
[root@fengxi myproject]# cp /etc/fstab .
[root@fengxi myproject]# svn add fstab //添加到版本控制中心
A fstab
[root@fengxi myproject]# svn commit -m "add fatab file" //把文件上传到服务器
Adding fstab
Transmitting file data .
Committed revision 1.
5.检查(到服务端看一下)
[root@localhost myproject]# cd /opt/
[root@localhost opt]# ls
myproject
[root@localhost opt]# cd myproject/
[root@localhost myproject]# ls //可以看到里面什么也没有
[root@localhost myproject]# svn update //把当前目录下的文件都更新到最新版
Updating '.':
A fstab
Updated to revision 1.
[root@localhost myproject]# ls
fstab
6.删除目录
[root@fengxi myproject]# svn delete fstab // 在本地删除
D fstab
[root@fengxi myproject]# svn commit -m "delete fstab file"
Deleting fstab
Committed revision 2.
[root@fengxi myproject]# ls //查看当前目录(里面没有东西)
6.检查服务端信息
[root@localhost myproject]# ls // 查看当前目录(有文件)
fstab
[root@localhost myproject]# svn up //更新目录文件
Updating '.':
D fstab
Updated to revision 2.
[root@localhost myproject]# ls //查看当前目录(没有文件)
7.查看变更日志
##客户端
[root@fengxi myproject]# svn log
------------------------------------------------------------------------
##服务端
[root@localhost myproject]# svn log
------------------------------------------------------------------------
r2 | lsk | 2020-11-19 03:04:40 +0800 (Thu, 19 Nov 2020) | 1 line
delete fstab file
------------------------------------------------------------------------
r1 | lsk | 2020-11-19 02:59:12 +0800 (Thu, 19 Nov 2020) | 1 line
add fatab file
------------------------------------------------------------------------
Windows中使用SVN
官网 https://tortoisesvn.net/index.zh.html
下载TortoiseSVN 并安装
简明教程 http://www.jianshu.com/p/6b3b7b915332
1、下载TortoiseSVN 并安装an装
点击下载,安装与自己电脑相符的版本(和语言包)
安装完毕后,在任意地方右键查看快捷菜单。发现TortoiseSVN即表示安装成功
2、svn导出
首先创建一个空文件夹。在空文件夹内右键,选择SVN检出
看到这个界面,填入版本库地址,选择确定
输入你的账号密码,记得勾选保存认证,不然每次操作都会让你输入
查看服务端
[root@localhost myproject]# pwd
/opt/myproject
[root@localhost myproject]# ls
test.txt
[root@localhost myproject]# cat test.txt
windows
test
右击,点 Edit with Notepad++ 打开
3、svn提交
添加new进行修改
发现现在变成了红色,红色表示已修改
右击,点 SVN提交
查看
[root@localhost myproject]# svn up
Updating '.':
U test.txt
Updated to revision 5.
[root@localhost myproject]# cat test.txt
windows
test
new
提交完毕后,可以发现又恢复到了绿色
右击新建文本文档,可以看出是蓝色的。蓝色表示不属于版本库的未知文件,未知文件是不能提交的
在文件内,随便写入内容保存。右击点 TortoiseSVN,再点击 加入,刷新一下
增加完毕后,变成了绿色对勾,表示新增加的版本库文件
[root@localhost myproject]# svn up
Updating '.':
A windows.txt
Updated to revision 6.
[root@localhost myproject]# cat windows.txt
111