Linux svn Command

Linux 命令大全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

# Ubuntu/Debian
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

svn checkout [Repository URL] [Local Directory]
# 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

svn update
# 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 added
  • M: Modified file
  • D: Deleted file
  • ?: Unversioned file
  • !: Missing file

Add Files

Place new files under version control:

Example

svn addFile name
# 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

svn log
# 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

# Compare working copy with the base revision
svn diff
# Compare two revisions
svn diff -r 100:200

Revert Changes

Discard local modifications:

Example

svn revertFile name
# Revert all changes
svn revert -R .

Resolve Conflicts

Conflicts may occur when multiple people modify the same file:

Example

# View conflict files
svn status
# Mark as resolved after resolving the conflict
svn resolve --acceptworking conflict file

Advanced Operations

Branching and Merging

Example

# Create a branch
svn copySource URL Target URL-m "Branch creation description"

# Merge branch
svn mergeSource URL[@Revision]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 tag for version 1.0"

Property Management

Example

# Set property
svn propset svn:keywords "Date Rev Author"File name

# View property
svn propgetsvn:keywords file name

Practical Tips

  1. Ignore files: Createsvn:ignoreproperty to exclude files that do not need version control

    svn propset svn:ignore "*.log" .
  2. View detailed file information:

    svn info 文件名
  3. Export a clean copy(without the .svn directory):

    svn export 仓库URL 本地目录
  4. Clean up the working copy:

    svn cleanup

Common Problem Resolution

Authentication Failure

Example

# Delete saved authentication information
rm -rf ~/.subversion/auth/

Working Copy Lock

svn cleanup

Conflict Resolution Process

  1. Update the working copy:svn update
  2. Manually resolve conflicts (edit the file)
  3. Mark as resolved:svn resolve --accept working 文件名
  4. Commit the changes:svn commit -m "解决冲突"

Best Practices

  1. Update the working copy before committing
  2. Write meaningful commit messages
  3. Commit small changes frequently rather than submitting a large number of modifications at once
  4. Use branches for feature development
  5. 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.


Linux 命令大全Complete Linux Command Reference

Other Extensions