一、安装SVN
[root@ShuaiJhou ~]# yum install -y subversion
[root@ShuaiJhou ~]# cat /etc/services | grep svn
svn 3690/tcp # Subversion
svn 3690/udp # Subversion
svnetworks 2973/tcp # SV Networks
svnetworks 2973/udp # SV Networks
svnet 3413/tcp # SpecView Networking
svnet 3413/udp # SpecView Networking
ml-svnet 4171/tcp # Maxlogic Supervisor Communication
[root@ShuaiJhou ~]#
[root@ShuaiJhou ~]# mkdir /opt/TtdProject #存放版本库的主目录
[root@ShuaiJhou ~]# ls /opt/TtdProject/
[root@ShuaiJhou ~]# ls -d /opt/TtdProject/
/opt/TtdProject/
[root@ShuaiJhou ~]#
创建两个版本库
[root@ShuaiJhou ~]# svnadmin create /opt/TtdProject/lv.zhou.cn
[root@ShuaiJhou ~]# svnadmin create /opt/TtdProject/lv.shuai.cn
[root@ShuaiJhou ~]# ll /opt/TtdProject/
total 0
drwxr-xr-x 6 root root 86 Jul 11 17:16 lv.shuai.cn
drwxr-xr-x 6 root root 86 Jul 11 17:15 lv.zhou.cn
[root@ShuaiJhou ~]#
[root@ShuaiJhou ~]# ls /opt/TtdProject/lv.shuai.cn/
conf db format hooks locks README.txt
db目录:就是所有版本控制的数据存放文件
hooks目录:放置hook脚本文件的目录
locks目录:用来放置subversion监控锁定数据的目录,用来追踪存取文件库的客户端
format文件:是一个文本文件,里面只放了一个整数。表示当前文件库配置的版本号
conf目录:是这个仓库的配置文件(仓库的用户访问账号、权限等),也是我们要关注的配置文件
[root@ShuaiJhou ~]# ls /opt/TtdProject/lv.shuai.cn/conf/
authz passwd svnserve.conf
authz #认证权限相关
passwd #用户名和密码
svnserve.conf #服务器配置文件
[root@ShuaiJhou ~]#
针对不同版本库修改配置文件
[root@ShuaiJhou ~]# vim /opt/TtdProject/lv.shuai.cn/conf/svnserve.conf
[general]
anon-access = read #原先注释掉了,匿名用户可以读,使用none的话就是匿名用户不可以访问
改:20 # auth-access = write #这几行都要取消注释,认证用户可以写,可以是read,write,none
为:20 auth-access = write
改:27 # password-db = passwd #密码库文件,默认使用的是同一目录下的passwd文件作为用户密码库
为:27 password-db = passwd
改:34 # authz-db = authz #认证权限文件
为:34 authz-db = authz
改:39 # realm = My First Repository #登陆提示信息
为:39 realm =lv.shuai.cn
注意:此配置文件的所有内容必须顶格,否则会报错
配置用户和密码及认证权限
[root@ShuaiJhou ~]# vim /opt/TtdProject/lv.shuai.cn/conf/passwd
[users]
uzi = 123456
faker=123456
mata=123456
#末尾添加上面三行
#对于部分版本,前面的[users]是有#号的,如果有#号,一定要取消,否则只能使用匿名用户登录,客户端登录不会出现登录窗口或密码提示,除非在配置文件将anon设置为none,否则将返回一个错误
#这里的密码都是明文,没有加密
#设置用户和组的权限
[root@ShuaiJhou ~]# vim /opt/TtdProject/lv.shuai.cn/conf/authz
[groups] #此行默认存在了
Check = uzi,faker #定义组,在[groups]下面添加
#用户组格式 用户组名 = 用户1,用户2
#一个组可以包含多个用户,英文逗号间隔,用户名必须是在passwd中存在的
[/] #/表示我当前所在版本库目录,这里代表lv.shuai.cn
mata=rw
@check=r #@Check表示这个组的权限,就是上面定义的组的成员
* = #除了上面的有赋予权限成员之外,其他的成员都没有权限
SVN目录格式:
[/目录名]
@用户组名 =权限
用户名 =权限
*=
服务SVN启动及创建测试代码
[root@ShuaiJhou ~]# svnserve -d -r /opt/TtdProject/
#启动了所有版本库, 再 –r。如果只需要某一个版本库,
后面添加 /opt/TtdProject/lv.shuai.cn/ 的版本库即可 -d=daemon -r=root of directory of save指定根目录
[root@ShuaiJhou ~]# ps -aux | grep svn
root 1391 0.0 0.0 180716 804 ? Ss 17:30 0:00 svnserve -d -r /opt/TtdProject/
root 1393 0.0 0.0 112704 968 pts/0 S+ 17:31 0:00 grep --color=auto svn
[root@ShuaiJhou ~]# netstat -antup | grep svn
tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 1391/svnserve
[root@ShuaiJhou ~]#
使用svn导入测试代码
导入测试代码格式: svn [选项] 源码 svn://server ip/项目名
常见的选项:
import #将未版本化的文件纳入版本控制并提交
checkout #从版本库中检出一个修订版
update #更新工作拷贝
add,delete,copy,move #增、删、复制、移动文件或目录
status #检查状态差异
diff #检查文件行级详细差异
revert #恢复
resolve #解决冲突
switch #切换工作拷贝对应的版本库分支
log #查看历史记录
list #显示文件目录
cat #查看某个文件内容
[root@ShuaiJhou ~]# mkdir localsvn
[root@ShuaiJhou ~]# cd localsvn/
[root@ShuaiJhou localsvn]# touch 1.html 2.html
[root@ShuaiJhou localsvn]# svn import /root/localsvn/ file:///opt/TtdProject/lv.shuai.cn/ -m "first edit"
Adding 1.html
Adding 2.html
Committed revision 1.
[root@ShuaiJhou localsvn]#
#本地导入代码,使用file,仅仅能在服务器本地导入, -m=messages,类似注释,首次加入代码使用import
代码取出
[root@ShuaiJhou ~]# svn checkout svn://192.168.31.62/lv.shuai.cn/ downsource
Authentication realm: <svn://192.168.31.62:3690> lv.shuai.cn
Password for 'uzi':
-----------------------------------------------------------------------
ATTENTION! Your password for authentication realm:
<svn://192.168.31.62:3690> lv.shuai.cn
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)? no
A downsource/1.html
A downsource/2.html
Checked out revision 1.
[root@ShuaiJhou ~]# cd downsource/
[root@ShuaiJhou downsource]# ls
1.html 2.html
[root@ShuaiJhou downsource]#
[root@ShuaiJhou downsource]# touch 5.html
[root@ShuaiJhou downsource]# svn add 5.html
A 5.html
[root@ShuaiJhou downsource]# svn commit -m "second edit"
Authentication realm: <svn://192.168.31.62:3690> lv.shuai.cn
Password for 'uzi':
-----------------------------------------------------------------------
ATTENTION! Your password for authentication realm:
<svn://192.168.31.62:3690> lv.shuai.cn
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)? no
svn: E170001: Commit failed (details follow):
svn: E170001: Authorization failed
[root@ShuaiJhou downsource]#
拓展:commit,SVN的提交是将在工作空间做的修改进行提交,包括文件内容的修改,文件或目录的添加,删除,命名,移动等操作。开发项目时,你会在工作拷贝中修改项目的代码,你总要把修改之后做过的改动又存回到项目仓库中去。这个过程称为“提交”。提交是将你对工作拷贝所作的所有改动发送并存储到中央项目仓库中。
add 功能:向拷贝文件所在的文件夹中添加新的文件,并作标识,是新添加的,下一步提交时将一并提交到Subversion版本库中去。简单的说就是将一新文件加入svn,你添加再提交后该文件就进入subversion版本中去了。
checkout:check out导出获得文件后,导出的文件仍处于SVN版本控制中,与版本库保持关联,比如你可以进行Svn Update或者Svn Commit操作,checkout是第一次用,后面的用法就是更新。
二、搭建GIT服务器及使用
[root@ShuaiJhou ~]# yum install -y git
#服务端用户创建空仓库创建
[root@ShuaiJhou ~]# useradd -m git
[root@ShuaiJhou ~]# echo git:123456 | chpasswd
[root@ShuaiJhou ~]# su git
[git@ShuaiJhou root]$ cd
[git@ShuaiJhou ~]$ mkdir CwProject.git
[git@ShuaiJhou ~]$ pwd
/home/git
[git@ShuaiJhou ~]$ cd CwProject.git/
[git@ShuaiJhou CwProject.git]$
[git@ShuaiJhou CwProject.git]$ git init --bare
Initialized empty Git repository in /home/git/CwProject.git/
[git@ShuaiJhou CwProject.git]$ ll
total 12
drwxrwxr-x 2 git git 6 Jul 11 18:09 branches
-rw-rw-r-- 1 git git 66 Jul 11 18:09 config
-rw-rw-r-- 1 git git 73 Jul 11 18:09 description
-rw-rw-r-- 1 git git 23 Jul 11 18:09 HEAD
drwxrwxr-x 2 git git 242 Jul 11 18:09 hooks
drwxrwxr-x 2 git git 21 Jul 11 18:09 info
drwxrwxr-x 4 git git 30 Jul 11 18:09 objects
drwxrwxr-x 4 git git 31 Jul 11 18:09 refs
[git@ShuaiJhou CwProject.git]$ pwd
/home/git/CwProject.git
[git@ShuaiJhou CwProject.git]$
#### git基本使用
git config —global user.name “xxx” //登录用户名
git config —global user.email “xxx” //登录用户邮箱
git remote -v //查看远程仓库地址
git branch //不跟参数即查看分支
git branch x //跟参数即创建x分支
git status //查看文件状态
git add xxx //添加xxx文件到暂存区 跟参数 —all 则添加全部
git commit -m ‘xxx’ //将暂存区文件提交到本地仓库 xxx为说明
git checkout xxx //切换仓库
git pull origin xxx //拉取远程仓库
git push origin xxx //提交至远程仓库
git diff //查看是否有冲突文件
git merge xxx//合并xxx分支到当前分支
//备注 origin 是默认的远程版本库名称
使用流程
克隆代码
clone
撸代码
添加
add
提交
commit
推送前先拉取
pull
查看是否有文件冲突
diff
再推送至远程
push
网友评论