Linux svn Command
Complete Linux Command Reference
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 supports version rollback.
Analogy: Think of SVN as a time machine. It records every modification to every file in your project, just like save points in a game. You can return to any previous version at any time.
SVN Basic Concepts
Repository
The SVN repository is where all version data is stored, equivalent to a central database. It maintains the complete history of the project.
Working Copy
This is a copy of the project on your local machine. You can make modifications here, then commit the changes to the repository.
Revision
Each commit generates a globally unique revision number to identify a specific state of the project.
SVN Installation and Configuration
Install SVN
On most Linux distributions, you can install it via the package manager:
Example
sudo apt-get install subversion
# CentOS/RHEL
sudo yum install subversion
# Fedora
sudo dnf install subversion
Verify Installation
svn --version
Detailed Explanation of Common SVN Commands
Checkout Code
Get code from the SVN repository to your local machine:
Example
# Example:
svn checkout http://svn.example.com/svn/project/trunk myproject
Common options:
--username: Specify username--password: Specify password--non-interactive: Non-interactive mode
Update Code
Synchronize the local working copy with the latest version in the repository:
Example
# Update to a specific revision
svn update -r 1234
Commit Changes
Commit local changes to the repository:
svn commit -m "提交说明"
View Status
View the modification status of the working copy:
svn status
Status flag explanation:
A: New file addedM: Modified fileD: Deleted file?: Unversioned file!: Missing file
Add Files
Place new files under version control:
Example
# Add all new files in the current directory
svn add --force .
Delete Files
Delete files from version control:
svn delete 文件名
View Log
View commit history:
Example
# View the log of a specific file
svn logFile name
# Limit the number of displayed entries
svn log -l 10
Compare Differences (Diff)
View the content of changes:
Example
svn diff
# Compare two revisions
svn diff -r 100:200
Revert Changes
Discard local modifications:
Example
# Revert all changes
svn revert -R .
Resolve Conflicts
Conflicts may occur when multiple people modify the same file:
Example
svn status
# Mark as resolved after resolving the conflict
svn resolve --acceptworking conflict file
Advanced Operations
Branching and Merging
Example
svn copySource URL Target URL-m "Branch creation description"
# Merge branch
svn mergeSource URL[@Revision]Working copy path
Tag Management
Example
svn copy http://svn.example.com/svn/project/trunk
http://svn.example.com/svn/project/tags/1.0
-m "Create tag for version 1.0"
Property Management
Example
svn propset svn:keywords "Date Rev Author"File name
# View property
svn propgetsvn:keywords file name
Practical Tips
-
Ignore files: Create
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 Resolution
Authentication Failure
Example
rm -rf ~/.subversion/auth/
Working Copy Lock
svn cleanup
Conflict Resolution Process
- Update the working copy:
svn update - Manually resolve conflicts (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 submitting a large number of modifications at once
- Use branches for feature development
- Regularly back up the repository
SVN vs Git Comparison
| Feature | SVN | Git |
|---|---|---|
| Architecture | Centralized | Distributed |
| Speed | Slower | Faster |
| Branching/Merging | More 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 suitable for projects that require strict permission control and centralized management. By mastering these basic commands and concepts, you can efficiently use SVN for your daily version control work. Remember, the core of version control is frequent commits and good commit habits, which will provide a reliable safety net for your project development.
Other Extensions