Linux svn Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to install and use the Subversion (SVN) version control system on an Ubuntu 22.04 environment. You will initialize a local SVN repository, commit changes, update the repository, and revert changes as needed. The lab covers the essential SVN commands and their practical applications, providing a solid foundation for managing source code and collaborating on projects using SVN.

The lab starts by installing the Subversion package on Ubuntu 22.04. It then guides you through the process of initializing a local SVN repository, allowing you to manage your project files and track changes over time. You will learn how to commit new changes, update the repository with the latest changes, and revert any unwanted modifications. This hands-on experience with SVN will equip you with the necessary skills to effectively use this version control system in your development workflows.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux(("`Linux`")) -.-> linux/PackagesandSoftwaresGroup(["`Packages and Softwares`"]) linux(("`Linux`")) -.-> linux/FileandDirectoryManagementGroup(["`File and Directory Management`"]) linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux/BasicSystemCommandsGroup -.-> linux/echo("`Text Display`") linux/PackagesandSoftwaresGroup -.-> linux/apt("`Package Handling`") linux/FileandDirectoryManagementGroup -.-> linux/cd("`Directory Changing`") linux/FileandDirectoryManagementGroup -.-> linux/mkdir("`Directory Creating`") linux/BasicFileOperationsGroup -.-> linux/ls("`Content Listing`") linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") subgraph Lab Skills linux/echo -.-> lab-422940{{"`Linux svn Command with Practical Examples`"}} linux/apt -.-> lab-422940{{"`Linux svn Command with Practical Examples`"}} linux/cd -.-> lab-422940{{"`Linux svn Command with Practical Examples`"}} linux/mkdir -.-> lab-422940{{"`Linux svn Command with Practical Examples`"}} linux/ls -.-> lab-422940{{"`Linux svn Command with Practical Examples`"}} linux/sudo -.-> lab-422940{{"`Linux svn Command with Practical Examples`"}} end

Install Subversion (SVN) on Ubuntu 22.04

In this step, we will install the Subversion (SVN) version control system on the Ubuntu 22.04 environment.

First, let's update the package index and install the Subversion package:

sudo apt-get update
sudo apt-get install -y subversion

Example output:

Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
...
Fetched 324 kB in 1s (324 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libapache2-mod-svn libsvn1 perl-modules-5.34 python3-subversion
Suggested packages:
  subversion-tools
The following NEW packages will be installed:
  libapache2-mod-svn libsvn1 perl-modules-5.34 python3-subversion subversion
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 4,197 kB of archives.
After this operation, 16.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
...

After the installation is complete, we can verify the Subversion version:

svn --version

Example output:

svn, version 1.14.1 (r1943681)
   compiled Aug 10 2022, 13:12:26 on x86_64-pc-linux-gnu

Copyright (C) 2022 The Apache Software Foundation.
This software consists of contributions made by many people;
see the NOTICE file for more information.

Subversion is open source software, see http://subversion.apache.org/

Now, Subversion is successfully installed on the Ubuntu 22.04 environment.

Initialize a Local SVN Repository

In this step, we will initialize a local Subversion (SVN) repository on the Ubuntu 22.04 environment.

First, let's create a directory to host the local SVN repository:

mkdir ~/project/svn-repo

Now, we can initialize the SVN repository in the ~/project/svn-repo directory:

cd ~/project/svn-repo
svnadmin create .

Example output:

$ cd ~/project/svn-repo
$ svnadmin create .

The svnadmin create . command initializes a new Subversion repository in the current directory.

Next, let's verify the repository structure:

ls -l ~/project/svn-repo

Example output:

total 16
drwxr-xr-x 2 labex labex 4096 Apr 12 10:12 conf
drwxr-xr-x 2 labex labex 4096 Apr 12 10:12 db
drwxr-xr-x 2 labex labex 4096 Apr 12 10:12 format
drwxr-xr-x 2 labex labex 4096 Apr 12 10:12 hooks
drwxr-xr-x 2 labex labex 4096 Apr 12 10:12 locks
-rw-r--r-- 1 labex labex   12 Apr 12 10:12 README.txt

The repository structure includes several directories and a README.txt file, which are used to manage the repository configuration, database, and hooks.

Now, the local SVN repository is initialized and ready for use.

Commit, Update, and Revert Changes in SVN

In this step, we will learn how to commit, update, and revert changes in the Subversion (SVN) repository.

First, let's create a new file in the SVN repository:

cd ~/project/svn-repo
echo "This is a test file." > test.txt

Now, we can add the new file to the SVN repository:

svn add test.txt

Example output:

A         test.txt

Next, let's commit the changes to the repository:

svn commit -m "Add test.txt file"

Example output:

Adding         test.txt
Transmitting file data .
Committed revision 1.

The svn commit command uploads the changes to the SVN repository with the provided commit message.

Now, let's make a change to the test.txt file and update the repository:

echo "Updated test file." >> test.txt
svn update

Example output:

U    test.txt
Updated to revision 2.

The svn update command downloads the latest changes from the repository and applies them to the local working copy.

Finally, let's revert the changes to the test.txt file:

svn revert test.txt
cat test.txt

Example output:

Reverted 'test.txt'
This is a test file.

The svn revert command discards the local changes and restores the file to the last committed state.

Through these operations, we have learned how to commit, update, and revert changes in the SVN repository.

Summary

In this lab, you learned how to install Subversion (SVN) on Ubuntu 22.04, initialize a local SVN repository, and manage changes using SVN commands such as commit, update, and revert. You created a local SVN repository, learned to commit new files, update the repository, and revert changes as needed. These skills are essential for version control and collaborative development using Subversion.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like