赞
踩
开发人员经常会上传代码,或者改对代码做一些更改。svn就是用来将修改后的代码更新到服务器上的。下面就来看一下怎么在Linux环境下搭建svn服务(subversion)
- yum install -y subversion //安装
-
- mkdir -p /data/svnroot/myproject // 创建版本库
-
- svnadmin create /data/svnroot/myproject 创建svn资源仓库
-
- vim/data/svnroot/myproject/conf #authz为权限配置文件,passwd为密码文件
-
- vim authz//配置文件改为如下
- [groups]
- admin = test
- [/]
- @admin = rw 组的用户
- * = r 其他以外的用户
- 扩展:
- [myproject:/] 如果svnroot下面有多个子目录可以用这个指定项目目录
- test = rw
-
- 设置账户密码:
- vim passwd
- test = test1234 (前面不要有空格不然无法连接)
-
- vim svnserver.conf
- [general]
- anon-access = none 匿名用户无法登陆
- auth-access = write 授权的用户拥有写权限
- password-db = passwd 指定passwd文件
- authz-db = authz 指定权限配置文件
- realm = /data/svnroot/myproject 指定项目目录
-
- 启动svn
- svnserve -d -r /data/svnroot/ //-d以后台模式启动,-r,指定目录
-
- 查看是否启动:监听3698端口
- netstat -lntp
- tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 19138/svnserve
-
-

- 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 //查看变更日志
客户端window使用svn上传
1:去官网下载svn https://tortoisesvn.net/
- 在window上创建一个文件夹
- 右键checkout
- 输入url 格式为:svn://IP/项目名称
- 上传代码操作
- 创建一个1.txt,然后右键svn有个add,添加,然后commit 上传写上描述
- 服务器上运行svn update即可
SVN的优点:
1、采用集中式,易于管理,保证安全性;
2、管理方便,逻辑明确,理念符合常规思维;
3、代码的一致性高;
4、适合人数不多的项目开发;
5、允许一个文件有任意多的可命名属性,会关注所有的文件类型;
6、支持二进制文件,更容易处理大文件;
7、支持空目录。
SVN的缺点:
1、服务器压力太大,数据库容量暴增;
2、必须连接在服务器上,否则基本不能工作、提交、对比、还原等;
3、不适合开源开发。
Git的优点:
1、适合分布式开发,强调个体;
2、公共的服务器压力和数量都不会太大;
3、速度快, 成熟的架构,开发灵活;
4、任意两个开发者之间可以很容易的解决冲突;
5、离线工作,管理代码成本低,不需要依赖服务器;
6、部署方便。基本上下个命令就可以用;
7、良好的分支机制,可以让主干代码保持干净。
Git的缺点:
1、资料少,学习成本比较大,学习周期比较长,要求人员素质比较高;
2、不符合常规思维;
3、代码保密性差,一旦开发者把整个库克隆下来就可以完全公开所有代码和版本信息。
- 安装:
- yum install -y git
-
- 创建一个项目
- mkdir /data/gitroot/
-
- 初始化仓库:
- git init
-
- 创建文件测试:
- touch 1.txt |echo "12312">1.txt
-
- 把1.txt添加标志
- git add 1.txt
-
- 上传至仓库
- git commit -m "add 1.txt"
-
- 查看提交记录:
- git log
- commit c46f8980e76cf5aea20e9501923d87167cb76379
- Author: root <978464597@qq.com>
- Date: Fri Sep 21 14:39:46 2018 +0800
-
- add
-
-
- 如果想回退版本库
- git reset --hard c46f89 //后面跟的是commit字符串,简写即可
-
- 如果不小心删除了1.txt,使用下面命令即可恢复
- git checkout -- 1.txt //前提要记得文件名
-
-
- 如果你add添加错了,但没有commit,可以使用以下命令返回上一次的状态
- git reset HEAD 1.txt
- git checkout 1.txt
-
- [root@study gitroot]# git add 1.txt //添加
- [root@study gitroot]# git status //查看状态,差提交
- # On branch master
- # Changes to be committed:
- # (use "git reset HEAD <file>..." to unstage)
- #
- # modified: 1.txt
- #
- [root@study gitroot]# git reset HEAD 1.txt //取消
- Unstaged changes after reset:
- M 1.txt
- [root@study gitroot]# git checkout 1.txt //再次检查
- [root@study gitroot]# git status //查看状态是空
- # On branch master
- nothing to commit, working directory clean
- [root@study gitroot]#
-
-
-
- 如果你想真正的删除文件,需要先删除后提交才能算删除。
- 1.git rm 1.txt 删除
- 2. git commit -m "rm 1.txt" 确认提交
-
-

我们可以把仓库放在其他地方。
1.首先需要去gitlub官网上注册一个账号 官网:https://github.com
2.注册完登录后去setting那里添加ssh本机秘钥
3.然后创建自己的项目库New repository
4.一般创建完自己项目库后,他会有教程
5.试下本地传文件去远程库把
[root@study gitroot]# ls 1.txt [root@study gitroot]# touch 2.txt |echo "1231231231231" >2.txt 创建 [root@study gitroot]# git add 2.txt 添加 [root@study gitroot]# git commit -m "add src " 上传 [master c25e6b9] add src 1 file changed, 1 insertion(+) create mode 100644 2.txt 下面这个就是把本地推送到远程的地址,https://网址/账号名/账号下的git库 [root@study gitroot]# git remote add origin https://github.com/skycity1234/gitroot.git [root@study gitroot]# git push -u origin master 推送上去 Username for 'https://github.com': skycity1234 输入账号密码 Password for 'https://skycity1234@github.com': Counting objects: 6, done. Compressing objects: 100% (3/3), done. Writing objects: 100% (6/6), 427 bytes | 0 bytes/s, done. Total 6 (delta 0), reused 0 (delta 0) remote: remote: Create a pull request for 'master' on GitHub by visiting: remote: https://github.com/skycity1234/gitroot/pull/new/master remote: To https://github.com/skycity1234/gitroot.git * [new branch] master -> master Branch master set up to track remote branch master from origin. [root@study gitroot]#6.查看下gitlub是否有我们上传的文件(这里看到我们的上传的2.txt,时间是3分钟前)
- 多了个clone克隆的意思加远程仓库地址
- [root@study test]# git clone https://github.com/skycity1234/gitroot.git
- Cloning into 'gitroot'...
- remote: Enumerating objects: 6, done.
- remote: Counting objects: 100% (6/6), done.
- remote: Compressing objects: 100% (3/3), done.
- Unpacking objects: 100% (6/6), done.
- remote: Total 6 (delta 0), reused 6 (delta 0), pack-reused 0
- [root@study test]# ls
- gitroot
- [root@study test]# cd gitroot/
- [root@study gitroot]# ls
- 1.txt 2.txt
- [root@study gitroot]#
- [root@study gitroot]# git branch 查看
- * master
- [root@study gitroot]# git branch slave 创建slave
- [root@study gitroot]# git branch
- * master
- slave
- [root@study gitroot]# git checkout slave 切换
- Switched to branch 'slave'
- [root@study gitroot]# git branch
- master 可以看到*号改变了代表切换到了slave下
- * slave
- [root@study gitroot]# ls
- 1.txt 2.txt
- [root@study gitroot]# cat 1.txt
- 123123
- [root@study gitroot]# echo "abcd" > 1.txt 修改文件内容
- [root@study gitroot]# cat 1.txt
- abcd
- [root@study gitroot]# git branch 目前在slave上
- master
- * slave
- [root@study gitroot]# git add 1.txt 添加上传
- [root@study gitroot]# git commit -m "change 1.txt"
- [slave f870962] change 1.txt
- 1 file changed, 1 insertion(+), 1 deletion(-)
- [root@study gitroot]# ls
- 1.txt 2.txt
- [root@study gitroot]# git checkout master 切换会主分支
- Switched to branch 'master'
- [root@study gitroot]# ls
- 1.txt 2.txt
- [root@study gitroot]# cat 1.txt 查看1.txt内容,可以看到跟上从分支是不一样的
- 123123
- [root@study gitroot]# git checkout slave
- Switched to branch 'slave'
- [root@study gitroot]# cat 1.txt
- abcd
- [root@study gitroot]#

- git checkout master //合并分支之前,先切换到目标分支
-
- git merge slave //把slave分支合并到了master
-
- git branch -d slave//删除分支
-
- git branch -D slave //强制删除
- 对于分支的应用,建议大家以这样的原则来: master分支是非常重要的,线上发布代码用这个分支,平时我们开发代码不要在这个分支上。
- 创建一个dev分支,专门用作开发,只有当发布到线上之前,才会把dev分支合并到master
- 开发人员应该在dev的基础上再分支成个人分支,个人分支(在自己pc上)里面开发代码,然后合并到dev分支
- 对于git push分支分两种情况
- 当本地分支和远程分支一致时 git push会把所有本地分支的变更一同推送到远程
- 如果想只推送一个分支,使用git push origin branch-name
- 当本地分支比远程分支多,默认git push 只推送本地和远程一致的分支,想要把多出来的本地分支推送到远程时,使用git push origin branch-name 如果推送失败,先用git pull抓取远程的新提交
- git clone的时候默认只把master分支克隆下来,如果想把所有分支都克隆下来,需要手动创建,在本地创建和远程分支对应的分支,使用git checkout -b branch-name origin/branch-name,本地和远程分支的名称要一致
github毕竟是公开的,而私有仓库又得花钱买。所以我们可以想办法搭建一个私有的,只自己公司使用的。Gitlab是个不错的选择。在介绍它之前,先讲述一下命令行的git服务器 找一台服务器,
gitlab官网 https://about.gitlab.com/gitlab-com/
官方安装文档 https://about.gitlab.com/installation/?version=ce#centos-7 (ce/ee) 要求服务器内存不少于2g
- vim /etc/yum.repos.d/gitlab.repo//加入如下内容
-
- [gitlab-ce]
-
- name=Gitlab CE Repository
-
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
-
- gpgcheck=0
-
- enabled=1
-
- yum install -y gitlab-ce
-
- gitlab-ctl reconfigure
-
- netstat -lnpt //查看监听端口
- gitlab-ctl stop/restart/start/status //停止或者开启、重启
- 浏览器访问gitlab,输入ip即可
- 默认管理员root,无密码,它会让我们去定义一个密码
-
- gitlab常用命令 https://www.cnyunwei.cc/archives/1204
- gitlab备份 gitlab-rake gitlab:backup:create
-
- 备份目录在/var/opt/gitlab/backups
- gitlab 恢复 先停服务 gitlab-ctl stop unicorn ; gitlab-ctl stop sidekiq
- gitlab-rake gitlab:backup:restore BACKUP=xxxxx (这里是一个编号,即备份文件的前缀)
- 再启动服务 gitlab-ctl start

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。