GIT和SVN教程
各种版本控制工具的简单比较
| 特性 | CVS | SVN | GIT | 
|---|---|---|---|
| 并发修改 | 支持 | 支持 | 支持 | 
| 并发提交 | 不支持 | 支持 | 支持 | 
| 历史轨迹 | 不支持更名 | 支持更名 | 支持更名 | 
| 分布式 | 不支持 | 不支持 | 支持 | 
SVN
SVN服务端安装
下载地址:
https://www.visualsvn.com/server/download/
双击安装包,安装,选择好安装地址,

选中这两项。next

选择圈中的,

路径因人而异。端口我选择3030,这也是因人而异,最后点击install。

安装成功后的界面
新增仓库和用户

默认next。

选择ok。
客户端安装与配置
下载地址:
https://tortoisesvn.net/downloads.html
选择好安装目录,其他都是无脑next。

在任何一个文件夹下,右击鼠标,都会出现SVN checkout。表示SVN客户端安装完成。

选择SVNcheckout,跳出这个框。

填好仓库地址后,选择ok,跳出这个确认用户框。输入账户密码然后ok。

然后本地多了个.svn文件夹

SVN的基本操作
添加
我在本地新建了test.html
右击,

选择SVN commit。

勾选对勾
刷新SVN服务端

就多了test.html。
删除
删除刚才本地仓库创建的test.html,然后右击选择SVN commit。
刷新SVN服务端

修改
撤回刚才删除的test.html并修改,然后右击选择SVN commit

再刷先SVN服务端

git
说到git就会说到GitHub,因为GitHub是通过git这个工具来commit的,而GitHub网站就相当于SVN服务端。
git安装
在Windows上使用Git,可以从Git官网直接下载安装程序,(网速慢的同学请移步国内镜像),然后按默认选项安装即可。
安装完成后,在开始菜单里找到“Git”->“Git Bash”,蹦出一个类似命令行窗口的东西,就说明Git安装成功!

安装完成后,还需要最后一步设置,在命令行输入:
git config --global user.name "Your Name"
git config --global user.email "email@example.com"
如果使用GitHub(我一般都用GitHub做自己的项目仓库服务器,毕竟免费,自己代码也不值钱)
注意git config命令的--global参数,用了这个参数,表示你这台机器上所有的Git仓库都会使用这个配置,当然也可以对某个仓库指定不同的用户名和Email地址。
创建版本库
如果你用GitHub新建了一个仓库,


mkdir test
cd test
git init
git add README.md
git commit -m"first commit"
git remot add origin git@github.com:TUGOhost/test.git
git push -u origin master

如果遇到不错的项目,可以
git clone git@github.com:TUGOhost/test.git
服务端仓库克隆到本地。
时光机穿梭
我们已经成功地添加并提交了一个READM.md文件,现在,是时候继续工作了,于是,我们继续修改READM.md文件,添加内容如下:
test
现在,运行git status命令看看结果:

git status命令可以让我们时刻掌握仓库当前的状态,上面的命令输出告诉我们,READM.md被修改过了,但还没有准备提交的修改。
虽然Git告诉我们READM.md被修改了,但如果能看看具体修改了什么内容,自然是很好的。比如你休假两周从国外回来,第一天上班时,已经记不清上次怎么修改的READM.md,所以,需要用git diff这个命令看看:

git diff顾名思义就是查看difference,显示的格式正是Unix通用的diff格式,可以从上面的命令输出看到。
版本回退
git log查看我们的历史纪录

好了,现在我们启动时光穿梭机,准备把README.md回退到上一个版本,也就是第一次first commit的那个版本,怎么做呢?
首先,Git必须知道当前版本是哪个版本,在Git中,用HEAD表示当前版本,也就是最新的提交(注意我的提交ID和你的肯定不一样),上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100。

第一次写markdown文件名为1.md

命令git reflog用来记录你的每一次命令:

工作区和版本库
Git和其他版本控制系统如SVN的一个不同之处就是有暂存区的概念。
工作区(Working Directory)
就是你在电脑里能看到的目录,比如我的D:\test\文件夹就是一个工作区:

版本库(Repository)
工作区有一个隐藏目录.git,这个不算工作区,而是Git的版本库。
Git的版本库里存了很多东西,其中最重要的就是称为stage(或者叫index)的暂存区,还有Git为我们自动创建的第一个分支master,以及指向master的一个指针叫HEAD。

前面讲了我们把文件往Git版本库里添加的时候,是分两步执行的:
第一步是用git add把文件添加进去,实际上就是把文件修改添加到暂存区;
第二步是用git commit提交更改,实际上就是把暂存区的所有内容提交到当前分支。
因为我们创建Git版本库时,Git自动为我们创建了唯一一个master分支,所以,现在,git commit就是往master分支上提交更改。
你可以简单理解为,需要提交的文件修改通通放到暂存区,然后,一次性提交暂存区的所有修改。
撤销文件和删除文件
在你准备提交前,一杯咖啡起了作用,你猛然发现了stupid boss可能会让你丢掉这个月的奖金!
既然错误发现得很及时,就可以很容易地纠正它。你可以删掉最后一行,手动把文件恢复到上一个版本的状态。如果用git status查看一下:
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
    modified:   readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
你可以发现,Git会告诉你,git checkout -- file可以丢弃工作区的修改:
$ git checkout -- README.md
命令git checkout -- README.md意思就是,把README.md文件在工作区的修改全部撤销,这里有两种情况:
一种是README.md自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;
一种是README.md已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。
删除文件
git rm README.md
在Linux中使用SVN
开发人员经常会上传代码,或者改对代码做一些更改。svn就是用来将修改后的代码更新到服务器上的。下面就来看一下怎么在Linux环境下搭建svn服务(subversion)。
步骤:
1、检查是否已经有svn
2、安装subversion
3、检查是否安装成功
4、创建svn资源仓库
5、新增用户及密码,配置权限,配置资源库权限
6、启动或者重启服务
7、从机安装subversion
8、测试
一、检查是否已经有svn
如果没有安装就会是下面的样子,提示找不到命令。
[root@localhost ~]# svnserve --version
-bash: svnserve: command not found
如果已经安装,会显示版本信息:
[root@localhost ~]#  svnserve --version
svnserve, version 1.6.11 (r934486)
   compiled Aug 17 2015, 08:37:43
Copyright (C) 2000-2009 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).
The following repository back-end (FS) modules are available:
* fs_base : Module for working with a Berkeley DB repository.
* fs_fs : Module for working with a plain file (FSFS) repository.
Cyrus SASL authentication is available.
二、安装
在Linux下安装的是subversion,直接用yum 安装即可。
[root@localhost ~]#
[root@localhost ~]# yum install -y subversion
三、检查安装是否成功
同样用的是 svnserve –version成功安装会显示版本信息
[root@localhost ~]# svnserve --version
四、创建svn资源仓库
配置文件就是在这一步生成。
[root@localhost ~]# svnadmin create /svndir
[root@localhost ~]# cd /svndir/
[root@localhost svndir]# ls
conf  db  format  hooks  locks  README.txt
[root@localhost svndir]# cd conf/
[root@localhost conf]# ls
authz  passwd  svnserve.conf
五、新增用户及密码,配置权限
已经看到在仓库下面生成了三个文件
authz #权限配置文件
passwd #用户名密码文件
svnserve.conf #资源库配置文件
[root@localhost conf]# vim 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
yunwei = 123456
~
新增一行:
yunwei = 123456
新增用户“yunwei”,密码是“123456”
[root@localhost conf]# vim authz
[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
[/]
* = r
  @admin = rw
  dangerman =
[svndir:/]
@admin = rw
在[groups]下面加入:
- = r #所有用户有读权限
dangerman = ##危险分子?什么是危险分子?没有任何权限 
[svndir:/] ###定义目录,项目的根目录
- = rw
 
[root@localhost conf]# vim svnserve.conf
这个配置文件打开下面几行前面的注释,删除最前面的空格:
anon-access = read
auth-access = write
password-db = passwd
authz-db = authz
realm = My First Repository
六、启动或者重启服务
[root@localhost conf]# /etc/init.d/svnserve start
Starting svnserve:                                     [  OK  ]
如果要指定目录要加参数:
[root@localhost svndir]# mkdir /svndir/svn
[root@localhost svndir]# svnserve -d -r /svndir/svn  ####(只是看一下可以指定目录,这个实验不需要)
svnserve: Can't bind server socket: Address already in use
问题来了!!!问题来了:
显示Address already in use
原因在这里:svnserve -d -r /svndir/svn 这条命令就是指定目录的启动。但是前面已经启动一次了。解决办法:
[root@localhost svndir]# /etc/init.d/svnserve stop
Stopping svnserve:                                         [  OK  ]
[root@localhost svndir]# svnserve -d -r /svndir/
[root@localhost svndir]# ls
conf  db  format  hooks  locks  README.txt
[root@localhost svndir]# netstat -antlp | grep svn
tcp        0      0 0.0.0.0:3690                0.0.0.0:*                   LISTEN      5045/svnserve
七、测试,从机安装subversion
在次从机安装也安装一个subversion 用来测试。
注:
服务主机:192.168.1.65
从机:192.168.1.121
在从机上checkout 根目录
[root@localhost ~]# svn checkout svn://192.168.1.65/svndir/
Checked out revision 0.
需要注意的这里check的目录跟服务主机里面定义的[svndir]要一样。
[root@localhost ~]# svn checkout svn://192.168.1.65/svndir/
svn: URL 'svn://192.168.1.65/svndir' doesn't exist
如果出现在这个报错,就要检查服务主机的auth配置文件了:
如果配置文件的的目录指定的是[svndir:/],而且svndir的目录在根下(/svndir)
那启动的时候即嫑指定目录直接用/etc/init.d/svnserve start 启动即可。我们这里目录符合默认目录,不用指定了。直接用/etc/init.d/svnserve start,或者不用指定目录。
svnserve -d -r /svndir/ 这表示指定目录到/svndir/
目录不对应会报错。
7.1:在从机上从机:192.168.1.121上提交
[root@localhost ~]# ls
Desktop    Downloads  Pictures  svndir     Videos
Documents  Music      Public    Templates
[root@localhost ~]# cd svndir/
[root@localhost svndir]# ls
[root@localhost svndir]# touch xiao
[root@localhost svndir]# ls
xiao
[root@localhost svndir]# pwd
/root/svndir
[root@localhost svndir]# ls
xiao
[root@localhost svndir]# svn add /root/svndir/xiao
A         /root/svndir/xiao
[root@localhost svndir]# svn commit /root/svndir/xiao -m 1
Authentication realm: <svn://192.168.1.65:3690> My First Repository
Password for 'root':
Authentication realm: <svn://192.168.1.65:3690> My First Repository
Username: ^Csvn: Commit failed (details follow):
  n: Caught signal
[root@localhost svndir]# svn commit /root/svndir/xiao -m 1
Authentication realm: <svn://192.168.1.65:3690> My First Repository
Password for 'root':
Authentication realm: <svn://192.168.1.65:3690> My First Repository
Username: yunwei
Password for 'yunwei':
-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:
   <svn://192.168.1.65:3690> My First Repository
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
Adding         xiao
Transmitting file data .
Committed revision 1.
注意:
1、提交代码前,必须先cd到/root/svndir/(就是checkout下来的)目录里;
2、服务器上没有的文件,在客户端需要先add预提交,再commit,如果服务器端已有的文件,直接commit
预提交的命令:
 svn add /root/svndir/xiao
提交的命令:
svn commit /root/svndir/xiao -m 1
出现committed revision 1 提交成功了。
到服务端查看有没有提交成功:
服务主机:192.168.1.65
[root@localhost svndir]# svn checkout svn://192.168.1.65/svndir/
A    svndir/xiao
Checked out revision 1.
[root@localhost svndir]# ls
conf  db  format  hooks  locks  README.txt  svn  svndir
[root@localhost svndir]# cd svndir/
[root@localhost svndir]# ls
xiao
接下来测试更新:
从机:192.168.1.121:
[root@localhost svndir]# ls
xiao
[root@localhost svndir]# vim xiao
hello koby bryant !
~
修改了xiao 这个文件的内容,之前是空文件,现在加上一行内容。
然后重新提交:
[root@localhost svndir]# svn commit /root/svndir/xiao -m 2
Sending        xiao
Transmitting file data .
Committed revision 2.
服务器主机:192.168.1.65
[root@localhost svndir]# svn up
     xiao
Updated to revision 2.
[root@localhost svndir]# ls
xiao
[root@localhost svndir]# vim xiao
hello koby bryant !
~
内容已经更改。
因为是更改内容,目录和文件已经有了,所以不用checkout了,直接svn up就可以了。
7.2、在服务器主机:192.168.1.65上提交
[root@localhost svndir]# ls
xiao  yao
[root@localhost svndir]# pwd
/svndir/svndir
[root@localhost svndir]# svn add /svndir/svndir/yao
A         /svndir/svndir/yao
[root@localhost svndir]# svn commit /svndir/svndir/yao -m 3
Authentication realm: <svn://192.168.1.65:3690> My First Repository
Password for 'root':
Authentication realm: <svn://192.168.1.65:3690> My First Repository
Username: yunwei
Password for 'yunwei':
-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:
   <svn://192.168.1.65:3690> My First Repository
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
Adding         yao
Transmitting file data .
Committed revision 3.
注意:还是要cd到/svndir/svndir里面再预提交,然后提交。
显示Committed revision 3.就说明提交成功
到从机:192.168.1.121上更新看效果:
[root@localhost svndir]# svn up
A    yao
Updated to revision 3.
[root@localhost svndir]# ls
xiao  yao
[root@localhost svndir]# cat yao
hello rayallen
上面提交不管是在服务器主机上还是在从机上,都需要输入服务器主机的root用户密码,以及在conf文件里面设置的用户和密码。上面测试是用的文件测试,目录同样可以。
比如:
从机上:192.168.1.121
[root@localhost svndir]# mkdir xiaoyao
[root@localhost svndir]# ls
xiao  xiaoyao  yao
[root@localhost svndir]# svn add /root/svndir/xiaoyao/
A         /root/svndir/xiaoyao
[root@localhost svndir]# svn commit /root/svndir/xiaoyao/ -m 4
Adding         xiaoyao
Committed revision 4.
服务器主机上:192.168.1.65
[root@localhost svndir]# svn up
A    xiaoyao
Updated to revision 4.
[root@localhost svndir]# ls
xiao  xiaoyao  yao
至此,svn的安装配置测试就成功了
参考链接
https://blog.csdn.net/weixin_37998647/article/details/78686246
https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
https://www.imooc.com/learn/109
GIT和SVN教程的更多相关文章
- SVN教程 -- 基于自己学习记录
		
SVN教程 -- 基于自己学习记录 1. 概述 a. 什么是SVN? Apache Subversion 通常被缩写成 SVN,是一个开放源代码的版本控制系统.相较于 git ,svn 是集中式版本控 ...
 - Git和SVN之间的区别
		
如果你在读这篇文章,说明你跟大多数开发者一样对GIT感兴趣,如果你还没有机会来试一试GIT,我想现在你就要了解它了. GIT不仅仅是个版本控制系统,它也是个内容管理系统(CMS),工作管理系统等.如果 ...
 - git和svn有什么区别
		
如果你在读这篇文章,说明你跟大多数开发者一样对GIT感兴趣,如果你还没有机会来试一试GIT,我想现在你就要了解它了. GIT不仅仅是个版本控制系统,它也是个内容管理系统(CMS),工作管理系统等.如果 ...
 - 国内代码托管平台(Git和SVN)
		
Github(Git和SVN)https://github.com/ 可以说GitHub的出现完全颠覆了以往大家对代码托管网站的认识.GitHub不但是一个代码托管网站,更是一个程序员的SNS ...
 - 【从零开始】【Java】【1】Git和svn
		
闲聊 干活快一年了吧,感觉工作中能干的事情也有一点了,但总有种不通透的感觉,查一个问题,能一路查出一堆不明白的东西. 之前新建过文档是记录点点滴滴的知识的,使用上没问题了,但原理什么的还是不懂,想了想 ...
 - GIT GUI简易教程
		
GIT GUI简易教程 前言 之前一直想一篇这样的东西,因为最初接触时,我也认真看了廖雪峰的教程,但是似乎我觉得讲得有点多,而且还是会给我带来很多多余且重复的操作负担,所以我希望能压缩一下它在我工作中 ...
 - 项目版本管理Git使用详细教程
		
前言 记得刚开始做项目开发的时候都是一个人完成一个项目,单打独斗的开发,也不知道什么是团队开发,没有这个概念,随着工作后来知道公司里项目都是团队开发,这个时候这么多人怎么开发一个项目呢,难道用u盘拷贝 ...
 - Git使用详细教程(一)
		
很久不发博客,最近有兴趣想写点东西,但 Live Writer 不支持从Word复制图片,疯狂吐槽下 Git使用详细教程(一) Git使用详细教程(二) 该教程主要是Git与IntelliJ IDEA ...
 - GIT和SVN之间的区别及基本操作对比
		
1)GIT是分布式的,SVN不是: 这是GIT和其它非分布式的版本控制系统,例如 SVN,CVS等,最核心的区别.如果你能理解这个概念,那么你就已经上手一半了.需要做一点声明,GIT并不是目前第一个或 ...
 
随机推荐
- js的事件冒泡机制
			
js的事件冒泡机制呢,就是一个DOM树,一级一级向上冒的过程,最终是到document这个根节点这里.js的事件冒泡机制,就像是一个水泡在水底下,冒泡到水面的过程. 摘自醉清玄
 - c++ 动态规划(数塔)
			
c++ 动态规划(dp) 题目描述 观察下面的数塔.写一个程序查找从最高点到底部任意位置结束的路径,使路径经过数字的和最大. 每一步可以从当前点走到左下角的点,也可以到达右下角的点. 输入 5 13 ...
 - php--学习封装类  (一)(操作mysql数据库的数据访问)
			
<?php class DBDA //定义一个类 { //定义成员变量,不能直接定义,前面要加上public或者是private public $host = "localhost&q ...
 - 绿色版的mysql 下载安装配置方式
			
解压下载好的压缩包 下载地址 mysql-5.6.26-win64 绿色版 copy 一份my-default.ini改名字为my.ini为mysql的配置文件 打开my.ini 修改配置文件 默认的 ...
 - CoreCLR Host源码分析(C++)
			
废话不多说,直接上源码: 1.在托管程序集里面执行方法 HRESULT CorHost2::ExecuteAssembly(DWORD dwAppDomainId,//通过CreateAppDomai ...
 - ES 24 - 如何通过Elasticsearch进行聚合检索 (分组统计)
			
目录 1 普通聚合分析 1.1 直接聚合统计 1.2 先检索, 再聚合 1.3 扩展: fielddata和keyword的聚合比较 2 嵌套聚合 2.1 先分组, 再聚合统计 2.2 先分组, 再统 ...
 - Linux vim基本的使用方法
			
一.vim 的三种模式 (1) 插入模式 在插入模式中,才能输入文字:要进入插入模式,可以按键 “i”:如果要进入插入模式时,直接切换到下一行,可以输入“o”: (2) 命令模式 在命令模式中,主要进 ...
 - 二、Markdown基本语法
			
目录 2.1 标题 一级标题 二级标题 三级标题 2.2 加粗 2.3倾斜 2.4 高亮 2.5 上标 2.6 下标 2.7 代码引用(>式) 2.8 代码引用(```式) 2.9 代码引入(` ...
 - 【React踩坑记一】React项目中禁用浏览器双击选中文字的功能
			
常规项目,我们只需要给标签加一个onselectstart事件,return false就可以 例: <div onselectstart="return false;" & ...
 - pytest
			
pytest可以生成多种样式的结果:1.生成JunitXML格式测试报告:命令: --junitxml=path(相对路径)2.生成result log 格式的测试报告: 命令:--resultlog ...