Windows 7 安装 Subversion Server

Page content

以前我一直使用cvs开发,我比较喜欢cvs的功能和操作方式,但是默认的eclipse和cvsnt的命令行处理cvs文件不一致导致我每次都很麻烦,曾经有一次修改eclipse cvs插件使eclipse能够处理cvsnt的cvs文件,感觉还可以,但是闲麻烦。而eclipse的svn插件处理svn文件和命令行一行的方式,因此目录可以在两种方式下工作,这个太棒了。于是决定采用svn,当然svn的那些特性也是我改变的原因之一。

Subversion

首先下载svn server进行安装,这里采用CollabNet的Subversion,地址:http://www.open.collab.net/downloads/subversion/。

安装好后将svn的bin目录加入path环境变量中,这样就可以在任何目录调用。接下来安装svn服务。

sc create svnservice  binpath= “C:\Users\xylz\app\svn\bin\svnserve.exe –service -r D:\home\dev\svnroot” displayname= “SvnService” depend= Tcpip start= auto

注意sc的参数,这个一直是微软比较恶心的地方。“=”和前面的参数合起来是一个参数,与后面的值是有一个空格的。其中“D:\home\dev\svnroot”是SVN的根目录,以后文件都将在此目录中。

然后是初始化根目录,如果包含空格就用引号引起来。

svnadmin create D:\home\dev\svnroot

接下来就是认证了。进入svn根目录“D:\home\dev\svnroot”,一般个人开发就采用最简单的用户名和密码验证好了。进入svnserve.conf文件,将默认的注释打开即可。

[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz

这里匿名用户不能访问,认证用户可以读写,密码文件时passwd文件,权限是authz文件,这两个文件都在此根目录中。

修改密码文件passwd,这个比较简单,明文的用户名/密码。

[users]
xylz =passwd

接下来是修改权限,由于只有我一个人开发,个人机器,因此权限都放开吧。修改权限文件authz:

[/]
xylz = rw

好了,所有前期工作都完成了,现在可以启动服务了。

net start svnservice

剩下的就是使用SVN了。一般我喜欢在hosts文件中加入一个域名,这样就可以做到与IP无关了,将来将目录移到其它机器时只要修改相应的hosts文件即可。

在CVS时代keywords是自动开启的,而在SVN中需要手动打开,在文件”C:\Users\xylz\AppData\Roaming\Subversion\config” (Unix/Linux是 $HOME/.subversion/config)中修改成以下两项:

enable-auto-props = yes

添加需要自动解析属性的文件类型:

*.java = svn:eol-style=native;svn:keywords=Rev Date Id
*.xml = svn:mime-type=text/xml;svn:eol-style=native;svn:keywords=Rev Date Id
*.xsl = svn:mime-type=text/xml;svn:eol-style=native;svn:keywords=Rev Date Id
*.xsd = svn:mime-type=text/xml;svn:eol-style=native;svn:keywords=Rev Date Id
*.xjb = svn:mime-type=text/xml;svn:eol-style=native;svn:keywords=Rev Date Id
*.wsdl = svn:mime-type=text/xml;svn:eol-style=native;svn:keywords=Rev Date Id
*.properties = svn:mime-type=text/plain;svn:eol-style=native;svn:keywords=Rev Date Id
.checkstyle = svn:mime-type=text/xml;svn:eol-style=native;svn:keywords=Rev Date Id
.pmd = svn:mime-type=text/xml;svn:eol-style=native;svn:keywords=Rev Date Id
.ruleset = svn:mime-type=text/xml;svn:eol-style=native;svn:keywords=Rev Date Id
*.c = svn:eol-style=native;svn:keywords=Rev Date Id
*.cpp = svn:eol-style=native;svn:keywords=Rev Date Id
*.h = svn:eol-style=native;svn:keywords=Rev Date Id
*.dsp = svn:eol-style=CRLF
*.dsw = svn:eol-style=CRLF
*.sh = svn:eol-style=native;svn:executable;svn:keywords=Rev Date Id
*.bat = svn:eol-style=native
*.pl = svn:eol-style=native;svn:keywords=Rev Date Id
*.py = svn:eol-style=native;svn:keywords=Rev Date Id
*.cmd = svn:eol-style=native
*.txt = svn:eol-style=native;svn:mime-type=text/plain;svn:keywords=Rev Date Id
*.cat = svn:eol-style=native;svn:mime-type=text/plain
*.htm* = svn:eol-style=native;svn:mime-type=text/html;svn:keywords=Rev Date Id
ChangeLog = svn:eol-style=native;svn:mime-type=text/plain
README* = svn:eol-style=native;svn:mime-type=text/plain
LICENSE* = svn:eol-style=native;svn:mime-type=text/plain
NOTICE* = svn:eol-style=native;svn:mime-type=text/plain
TODO* = svn:eol-style=native;svn:mime-type=text/plain
KEYS* = svn:eol-style=native;svn:mime-type=text/plain
INSTALL* = svn:eol-style=native;svn:mime-type=text/plain
WHATSNEW* = svn:eol-style=native;svn:mime-type=text/plain
NEWS* = svn:eol-style=native;svn:mime-type=text/plain
COPYING = svn:eol-style=native;svn:mime-type=text/plain
*.png = svn:mime-type=image/png
*.jpg = svn:mime-type=image/jpeg
*.gif = svn:mime-type=image/gif
Makefile = svn:eol-style=native
*.css = svn:eol-style=native;svn:keywords=Rev Date Id
*.js = svn:eol-style=native;svn:keywords=Rev Date Id
*.jsx = svn:eol-style=native
*.cxf = svn:mime-type=text/xml;svn:eol-style=native;svn:keywords=Rev Date

参考资料

  • Subversion(SVN)自动展开关键字的方法
  • Subversion(SVN)安装指南