下面系统性地教你用最规范、最常用的方式创建 SVN 版本库(Repository),并直接给出各种系统下的一键命令和最佳实践。
1. 推荐的版本库结构(强烈建议直接照抄)
/myrepo ← 版本库根目录
├ trunk ← 主干,日常开发都在这里
├ branches ← 分支目录
│ ├ release-1.0 ← 发布分支
│ ├ feature-xxx ← 功能分支
│ └ hotfix-xxx ← 热修复分支
└ tags ← 标签目录(只读快照)
├ 1.0.0
├ 1.0.1
└ 2025.11.22
2. 创建版本库的 3 种常用方法(任选其一)
方法一:直接用 svnadmin create(最快,推荐)
# Linux / macOS
sudo mkdir -p /svn/repos
sudo svnadmin create /svn/repos/myproject
# Windows(管理员权限运行 cmd 或 PowerShell)
mkdir D:\svn\repos
svnadmin create D:\svn\repos\myproject
方法二:用 VisualSVN Server 图形化创建(Windows 最简单)
- 打开 VisualSVN Server Manager
- 右键 Repositories → Create New Repository
- 选 “Single-project repository” → 输入名字 myproject → 勾选 “Create default structure (trunk, branches, tags)” → 完成
方法三:一次性创建并导入标准结构(最规范)
# 第一步:创建空版本库
svnadmin create /svn/repos/myproject
# 第二步:一次性建立标准目录结构(推荐!)
svn mkdir -m "Initial structure" \
file:///svn/repos/myproject/trunk \
file:///svn/repos/myproject/branches \
file:///svn/repos/myproject/tags
# 第三步:把本地代码导入 trunk(假设当前目录就是项目代码)
cd /path/to/your/project
svn import . file:///svn/repos/myproject/trunk -m "Initial import"
3. 不同系统完整一键创建脚本
Ubuntu/Debian(含权限设置)
REPO=myproject
svnadmin create /svn/repos/$REPO
svn mkdir -m "Standard layout" \
file:///svn/repos/$REPO/trunk \
file:///svn/repos/$REPO/branches \
file:///svn/repos/$REPO/tags
chown -R www-data:www-data /svn/repos/$REPO # Apache 模式用
# chown -R subversion:subversion /svn/repos/$REPO # svnserve 模式用
CentOS/RHEL/Rocky/AlmaLinux
REPO=myproject
mkdir -p /var/svn/repos
svnadmin create /var/svn/repos/$REPO
svn mkdir -m "init" file:///var/svn/repos/$REPO/{trunk,branches,tags} --with-revprop svn:author=admin
chown -R apache:apache /var/svn/repos/$REPO
macOS(Homebrew)
brew install subversion
mkdir -p ~/svn/repos
svnadmin create ~/svn/repos/myproject
svn mkdir -m "init" file:///Users/$(whoami)/svn/repos/myproject/{trunk,branches,tags}
Windows PowerShell(管理员)
svnadmin create D:\svn\repos\myproject
svn mkdir -m "init" `
file:///D:/svn/repos/myproject/trunk `
file:///D:/svn/repos/myproject/branches `
file:///D:/svn/repos/myproject/tags
4. 创建完成后立刻验证
svn list file:///svn/repos/myproject
# 应该看到:
# branches/
# tags/
# trunk/
5. 立刻 checkout 使用
svn checkout file:///svn/repos/myproject/trunk myproject-work
# 或远程访问(根据你启动的服务方式):
# svn checkout svn://192.168.1.100/myproject/trunk
# svn checkout https://svn.yourcompany.com/myproject/trunk
现在你的 SVN 版本库已经完全就绪,结构最规范,后续开发、分支、打 tag 都最顺手。
如果你告诉我:
- 你用的是 Windows 还是 Linux?
- 准备用 svnserve 还是 Apache?
- 项目是大项目还是小项目?
我马上给你最现成的完整配置模板(包含权限、匿名只读等最常用设置)。