Files
Obsidian/MyselfDev/SVN 命令行操作汇总.md
T
coco 8b94d76799 a
2026-07-21 13:57:15 +08:00

705 lines
8.6 KiB
Markdown

---
title: "[SVN] 命令行操作汇总"
source: "https://blog.csdn.net/weixin_62160019/article/details/154430520"
author:
- "[[weixin_62160019]]"
published: 2025-11-05
created: 2026-04-02
description: "文章浏览阅读492次,点赞3次,收藏6次。【代码】[SVN] 命令行操作汇总。_svn 命令"
tags:
- "clippings"
---
### 基础概念
#### SVN 目录结构
```cobol
repository/
├── trunk/ # 主干,主要开发分支
├── branches/ # 分支目录
└── tags/ # 标签目录,用于发布版本
AI写代码
```
#### 常用选项说明
- `-m "message"` :提交信息
- `-r revision` :指定版本号
- `--username name` :指定用户名
- `--password pass` :指定密码
- `-q` :安静模式,减少输出
- `-v` :详细模式
---
### 仓库操作
#### 创建新仓库
```bash
# 在 SVN 服务器上执行
svnadmin create /path/to/repository
AI写代码bash
```
#### 导入 项目 (首次上传)
```bash
# 将本地文件夹导入到仓库
svn import /local/path https://svn.example.com/svn/repo/trunk -m "Initial import"
AI写代码bash
```
#### 检出工作副本
```bash
# 检出整个项目
svn checkout https://svn.example.com/svn/repo/trunk
# 检出到指定目录
svn checkout https://svn.example.com/svn/repo/trunk my_project
# 检出特定版本
svn checkout https://svn.example.com/svn/repo/trunk -r 123
# 简写形式 co
svn co https://svn.example.com/svn/repo/trunk
AI写代码bash
```
---
### 日常开发流程
#### 检查状态
```bash
# 查看工作副本状态
svn status
# 状态代码说明:
# ? 未版本控制
# A 已计划添加
# D 已计划删除
# M 已修改
# C 冲突
# ! 丢失或不完整
AI写代码bash
```
#### 更新工作副本
```bash
# 更新到最新版本
svn update
# 更新到特定版本
svn update -r 123
# 更新单个文件
svn update file.txt
# 简写形式 up
svn up
AI写代码bash
```
#### 提交更改
```bash
# 提交所有更改
svn commit -m "描述修改内容"
# 提交特定文件
svn commit file1.txt file2.txt -m "修改文件"
# 简写形式 ci
svn ci -m "提交信息"
AI写代码bash
```
---
### 文件操作
#### 添加文件
```bash
# 添加单个文件
svn add file.txt
# 添加文件夹(递归)
svn add folder/
# 添加所有未版本控制文件
svn add . --force
# 添加特定类型文件
svn add *.java
AI写代码bash
```
#### 删除文件
```bash
# 从版本控制删除(本地文件也会删除)
svn delete file.txt
svn delete https://192.168.xx.xxx/svn/test/Document/test.xlsx
# 仅从版本控制删除(保留本地文件)
svn delete file.txt --keep-local
# 简写形式 del 或 rm
svn del file.txt
AI写代码bash
```
#### 移动/重命名
```bash
# 移动/重命名文件
svn move old.txt new.txt
# 移动文件夹
svn move old_dir/ new_dir/
# 简写形式 mv
svn mv old.txt new.txt
AI写代码bash
```
#### 恢复文件
```bash
# 恢复未提交的修改
svn revert file.txt
# 恢复整个目录
svn revert . -R
# 恢复已删除的文件(未提交)
svn revert file.txt
AI写代码bash
```
---
### 分支与标签
#### 创建分支
```bash
# 从 trunk 创建分支
svn copy https://svn.example.com/svn/repo/trunk \
https://svn.example.com/svn/repo/branches/feature-branch \
-m "创建功能分支"
# 从特定版本创建分支
svn copy https://svn.example.com/svn/repo/trunk@123 \
https://svn.example.com/svn/repo/branches/feature-branch \
-m "从版本123创建分支"
AI写代码bash
```
#### 创建标签
```bash
# 创建发布标签
svn copy https://svn.example.com/svn/repo/trunk \
https://svn.example.com/svn/repo/tags/v1.0.0 \
-m "发布版本 v1.0.0"
AI写代码bash
```
#### 切换 分支
```bash
# 切换到分支
svn switch https://svn.example.com/svn/repo/branches/feature-branch
# 切换回主干
svn switch https://svn.example.com/svn/repo/trunk
AI写代码bash
```
#### 合并 更改
```bash
# 将分支合并到当前工作副本
svn merge https://svn.example.com/svn/repo/branches/feature-branch
# 合并特定版本范围
svn merge -r 100:200 https://svn.example.com/svn/repo/trunk
# 预览合并(不实际执行)
svn merge --dry-run https://svn.example.com/svn/repo/branches/feature-branch
AI写代码bash
```
---
### 查看与比较
#### 查看日志
```bash
# 查看提交日志
svn log
# 查看特定文件日志
svn log file.txt
# 查看最近5条日志
svn log -l 5
# 详细日志
svn log -v
# 特定日期范围
svn log -r {2023-01-01}:{2023-12-31}
AI写代码bash
```
#### 查看文件信息
```bash
# 查看文件详细信息
svn info
# 查看特定文件信息
svn info file.txt
# 查看远程文件信息
svn info https://svn.example.com/svn/repo/trunk/file.txt
AI写代码bash
```
#### 比较文件
```bash
# 比较工作副本与基础版本
svn diff
# 比较特定文件
svn diff file.txt
# 比较工作副本与特定版本
svn diff -r 123 file.txt
# 比较两个版本
svn diff -r 100:200 file.txt
# 比较分支
svn diff https://svn.example.com/svn/repo/trunk \
https://svn.example.com/svn/repo/branches/feature
AI写代码bash
```
#### 列出目录内容
```bash
# 列出工作副本内容
svn list
# 列出仓库内容
svn list https://svn.example.com/svn/repo/trunk
# 详细列表
svn list -v
# 递归列表
svn list -R
AI写代码bash
```
---
### 冲突解决
#### 处理冲突
```bash
# 更新时可能产生冲突
svn update
# 冲突文件状态:
# file.txt.mine 你的版本
# file.txt.rOLD 基础版本
# file.txt.rNEW 服务器版本
# 手动解决冲突后标记为已解决
svn resolve file.txt --accept working
# 接受特定版本
svn resolve file.txt --accept mine-full # 接受你的版本
svn resolve file.txt --accept theirs-full # 接受他人版本
AI写代码bash
```
#### 冲突选项
```bash
--accept ARG : 指定冲突解决方式
postpone 标记为稍后解决
base 接受基础版本
mine-full 接受我的版本
theirs-full 接受他人版本
mine-conflict 接受我的冲突部分
theirs-conflict 接受他人的冲突部分
AI写代码bash
```
---
### 权限与属性
#### 属性管理
```bash
# 设置属性
svn propset svn:keywords "Date Rev Author" file.txt
# 查看属性
svn propget svn:keywords file.txt
# 列出所有属性
svn proplist file.txt
# 删除属性
svn propdel svn:keywords file.txt
AI写代码bash
```
#### 忽略文件
```bash
# 设置忽略模式
svn propset svn:ignore "*.log
tmp/
*.tmp" .
# 查看忽略列表
svn propget svn:ignore .
# 从文件读取忽略模式
svn propset svn:ignore -F .svnignore .
AI写代码bash
```
---
### 实用技巧
#### 认证 缓存
```bash
# 避免重复输入密码
# 在 ~/.subversion/servers 中添加:
[global]
store-plaintext-passwords = yes
AI写代码bash
```
#### 大文件上传
```bash
# 设置大文件上传超时
svn import large_folder http://svn.example.com/repo -m "大文件" --config-option servers:global:http-timeout=3600
AI写代码bash
```
#### 清理工作副本
```bash
# 清理工作副本
svn cleanup
# 删除未版本控制文件
svn status | grep '^?' | awk '{print $2}' | xargs rm -rf
AI写代码bash
```
#### 导出无版本信息的代码
```bash
# 导出纯净代码(无.svn文件夹)
svn export https://svn.example.com/svn/repo/trunk ./exported_code
# 导出特定版本
svn export -r 123 https://svn.example.com/svn/repo/trunk ./exported_code
AI写代码bash
```
#### 查看仓库结构
```bash
# 递归查看仓库完整结构
svn list -R https://svn.example.com/svn/repo
AI写代码bash
```
---
### 常用 工作流 示例
#### 标准开发流程
```bash
# 1. 更新到最新
svn update
# 2. 进行修改
# ... 编辑文件 ...
# 3. 检查状态
svn status
# 4. 查看差异
svn diff
# 5. 提交更改
svn commit -m "功能描述"
AI写代码bash
```
#### 修复 bug 流程
```bash
# 1. 创建bug修复分支
svn copy https://svn.example.com/svn/repo/trunk \
https://svn.example.com/svn/repo/branches/hotfix-issue123 \
-m "创建issue123修复分支"
# 2. 切换到分支
svn switch https://svn.example.com/svn/repo/branches/hotfix-issue123
# 3. 修复并提交
# ... 修复bug ...
svn commit -m "修复issue123"
# 4. 合并回主干
svn switch https://svn.example.com/svn/repo/trunk
svn merge https://svn.example.com/svn/repo/branches/hotfix-issue123
svn commit -m "合并issue123修复"
AI写代码bash
```