Linux svn command
SVN (Subversion) is an open-source version control system used to manage the change history of files and directories. It helps development teams collaborate on projects, track code changes, and support version rollback.
By analogy, you can think of SVN as a time machine that records every change to every file in your project, like a save point in a game, letting you return to any previous version at any time.
Basic SVN concepts
Repository
An SVN repository is where all version data is stored, equivalent to a central database. It holds the project's complete history.
Working Copy
This is a copy of the project on your local machine where you can make changes and then commit them to the repository.
Revision
Each commit generates a globally unique revision number that identifies a specific state of the project.
SVN installation and configuration
Install SVN
On most Linux distributions, you can install it through the package manager:
Example
Ubuntu/Debian
sudo
apt-get install
subversion
CentOS/RHEL
sudo
yum install
subversion
Fedora
sudo
dnf
install
subversion
Verify the installation
svn --version
Details of common SVN commands
Checkout
Get code from an SVN repository to your local machine:
Example
svn checkout
[
Repository URL
]
[
Local directory
]
Example:
svn checkout
http:
//
svn.example.com
/
svn
/
project
/
trunk myproject
Common options:
--username: specify the username--password: specify the password--non-interactive: non-interactive mode
Update
Synchronize the local working copy with the latest version in the repository:
Example
svn update
Update to a specific revision
svn update
-r
1234
Commit
Commit local changes to the repository:
svn commit -m "提交说明"
Status
View the modification status of the working copy:
svn status
Status flag descriptions:
A: newly added fileM: modified fileD: deleted file?: unversioned file!: missing file
Add
Put new files under version control:
Example
svn add
File Name
Add all new files in the current directory
svn add
--force
.
Delete
Delete a file from version control:
svn delete 文件名
Log
View the commit history:
Example
svn log
View the log of a specific file
svn log
File Name
Limit the number of displayed entries
svn log
-l
10
Diff
View the changes:
Example
Compare the working copy with the base revision
svn diff
Compare two revisions
svn diff
-r
100
:
200
Revert
Discard local changes:
Example
svn revert
File Name
Revert all changes
svn revert
-R
.
Resolve
Conflicts can occur when multiple people modify the same file:
Example
View conflicting files
svn status
Mark as resolved after resolving conflicts
svn resolve
--accept
working conflicting files
Advanced operations
Branching and merging
Example
Create a branch
svn copy
source URL target URL
-m
"Create branch description"
Merge branches
svn merge
source URL
[
@
Version
]
working copy path
Tag management
Example
Create a tag (same syntax as creating a branch)
svn copy
http:
//
svn.example.com
/
svn
/
project
/
trunk
http:
//
svn.example.com
/
svn
/
project
/
tags
/
1.0
-m
"Create the version 1.0 tag"
Property management
Example
Set a property
svn propset
svn:keywords
"Date Rev Author"
File Name
View a property
svn propget
svn:keywords filename
Practical tips
-
Ignore files: Creating
svn:ignoreproperty to exclude files that do not need version controlsvn propset svn:ignore "*.log" .
-
View detailed file information:
svn info 文件名
-
Export a clean copy(without the .svn directory):
svn export 仓库URL 本地目录
-
Clean up the working copy:
svn cleanup
Common Problem Solutions
Authentication failure
Example
Delete saved authentication information
rm
-rf
~
/
.subversion
/
auth
/
Working copy locked
svn cleanup
Conflict resolution workflow
- Update the working copy:
svn update - Resolve the conflict manually (edit the file)
- Mark as resolved:
svn resolve --accept working 文件名 - Commit the changes:
svn commit -m "解决冲突"
Best Practices
- Update the working copy before committing
- Write meaningful commit messages
- Commit small changes frequently rather than a large batch at once
- Use branches for feature development
- Back up the repository regularly
SVN vs. Git Comparison
| Feature | SVN | Git |
|---|---|---|
| Architecture | Centralized | Distributed |
| Speed | Slower | Faster |
| Branching / Merging | Relatively complex | Simple and Efficient |
| Offline Work | Limited support | Full Support |
| Learning curve | Gentler | Steeper |
Summary
SVN is a powerful and stable version control system, especially suited for projects that require strict access control and centralized management. By mastering these basic commands and concepts, you can now use SVN efficiently for everyday version control work. Remember, the essence of version control is frequent commits and good commit habits, which will provide a reliable safety net for your project development.
Linux Command Reference