What is SVN version control system

Choosing the right version control system to work with your files might seem to be a complicated task. To help you select the version control system that will meet your objectives, we suggest that you consider a Subversion (SVN). Why is it worth your attention? First, SVN is an open-source and centralized version control system. Due to its more secure centralized approach, it is easier to control the coding process, and manage access to modified files. Second, you do not need to have a lot of space to store the files: You can keep only files to be updated on your local computer and then commit them to the server.

In the article, you can read about how SVN works, what advantages and disadvantages it has, and what basic commands you can execute to work with the files. And to make it easier for you to manage changes that you make and then commit to the SVN repository, you can use dbForge Source Control for SQL Server. In the article, we explain why it is better to use this database change management tool.

Types of version control systems

A version control system manages changes in a file or a set of files and organizes those changes in versions. There are three different types of version control systems:

  • Localized, which is deployed on your local computer. It stores file changes, which you made since the previous version, as a patch. Since data is stored locally, you may lose it in case of errors or any corruption.
  • Centralized, which stores all the versions of file changes within a single central server. Multiple users can have access to files on the server from their local computers and be aware of who checks out the files and what changes applies. However, if the server is down, the changes cannot be pulled or saved and may be lost. Thus, it is recommended that you have a backup.
  • Distributed, which allows users to clone a repository along with the full history of changes on their local computers. In case of any issues with the server, users can share their copy of the project version through the remote repository and thus, avoid losing any data.

How SVN works

SVN stands for Subversion. It is a centralized version control system distributed under an open-source Apache license. SVN allows multiple developers to have the current and recent versions of data, such as source files, in sync. It keeps track of every change users make on files. Thus, you can easily restore earlier versions and analyze the history of changes, identify who made file modifications, when, and why. This way the development is done much faster.

The workflow is the following: You check out a working copy of the files to your local computer. Then, you can make changes to the files in your working copy through an SVN client program, having access to SVN server, and verify that everything works properly. After that, you commit the changes directly to the central server repository. SVN central server stores the history of changes to the versioned data in the form of revisions. Thus, each time you update the file, the server creates its new version. If you want to update your local working copy with the latest changes, you need to pull the file from the central server. If you need the older version, you should roll back to the earlier revision.

How SVN works

Basic commands

You can perform operations either through the command-line interface or with the help of an SVN client. Here is the list of some basic SVN commands that help you easily and efficiently cope with data change management.

  • svn checkout/svn co URL
    Pulls source data to a local working copy from the repository. URL is a path to the data you want to check out. During the checkout, SVN creates a hidden .svn file that contains some repository details.
  • svn commit -m "commit reason"
    Saves the changes you have done in the working copy to the repository. In the -m "commit reason" part, you leave your comments explaining the commit.
  • svn admincreate
    Creates an empty repository.
  • svn list
    Displays all the files in the SVN repository without creating a new working copy.
  • svn add
    Adds a new file or directory to the SVN repository. Note that the file will be added after you commit it to the repository.
  • svn delete
    Removes the file from the working copy or repository. Note that the file will be deleted from the repository after you have done a commit.
  • svn status
    Displays a status of the working copy (modified, added, deleted).
  • svn log
    Displays log messages from the repository.
  • svn move
    Transfers a file from one directory to another, or renames a file.
  • svn update path
    Gets the latest changes from the repository to your working copy. path is a revision with which you want to synchronize your working copy. If you do not specify the revision, the changes will be retrieved from the HEAD revision.
  • svn diff
    Displays the differences between two revisions: your working copy and the copy from the central SVN repository.

How to check an SVN version

To find out the version of SVN server, you can do the following:

  • When accessing the server via the browser, switch to the SVN server repository and search for the version in the HTML source code.
  • When checking the server version by using the SVN client, run svn --version in the terminal.
How to check an SVN version

How to lock and unlock files

You may encounter a situation when your working copy differs from the one in the SVN server repository. For example, if you did not update your working copy with the latest changes from the SVN server repository and modified the file, you may face a conflict. However, if the text file, such as a readme file, is outdated, you can merge your local changes with the changes in the repository. In this case, no conflict arises, as your changes will be automatically merged with the latest copy from the repository. If you and other developer modify the same file, you can resolve the conflict manually by comparing the code and applying the required changes.

But if both of you modify the same graphic file, you cannot merge it, and one of you will lose your changes. Instead, you can lock the file. How does it work? You run a lock command that puts a flag on the file with which you are working. This lock informs that the file is blocked and only you can alter and commit it. Other users won't be able to modify, delete, or commit the file until you unlock it. Still, other users may be unaware of the locked file. Therefore, they should conduct a regular check of the file status.

To lock the file, run svn lock filename where filename is the path to the file you want to lock. If you want to lock the file that has already been locked by another user, you need to run the following command: svn lock --force filename.

How to lock the file in SVN

To check the status of the file, run svn status. This command will display the statuses of all files in the current directory. For example, A refers to added, M - to modified, L - to locked, C - to conflict, etc.

When you finished working on the file, you can unlock it by running svn unlock filename. After that, other users can start performing some operations on the file. If you want to commit the locked file, you can run the svn unlock --force command.

How to lock the file in SVN

Sometimes you can get an error message when working with the lock commands: Can't open file 'PATH/TO/YOUR/FILES/.svn/lock': Permission denied. It means that you ran the svn commands as a root user which is better to avoid. To resolve the issue, you need to reset file access rights and ownership on all your files in your directory, including the hidden .svn files. To achieve this, execute the commands in the following order:

# specify the path to your project
cd /path_to_your_project

# reset ownership rights
# replace user_and_group with your username and group
sudo find . -exec chown user_and_group {} \;

# reset permissions
# replace file_permissions with your file permissions
sudo find . -exec chmod file_permissions {} \;

# execute the cleanup command to repair your .svn folders
svn cleanup

Subversion cons and pros

Advantages of Subversion include:

  • Free open-source version control system.
  • Single server for the repository and its metadata. It allows users to store locally only those files, that they want to update and commit them directly to the server.
  • History of changes.
  • Faster synchronization of differences between the local copy and the one on the central server.

Disadvantages of Subversion include:

  • Manual resolution of conflicts (that may occur) when developers work on the same file which wastes a lot of their time.
  • Need in a direct connection to the central server repository; otherwise, committing changes cannot be performed.
  • Branches are structured as directories on the server.
  • Need in more storage. Creating a branch takes up much space as it produces a full copy of all the files.

Benefits of using dbForge Source Control

The market offers plenty of tools to work with changes in the SVN. However, one of the most convenient and efficient tools is - dbForge Source Control for SQL Server - using which change management is getting easier than ever. You can link your databases to the most widely-used version control systems, including SVN, and perform all operations within a single tool.

  • Boost developer productivity
  • Simplify the management of multiple developers working on the product
  • Automate complex and repeatable processes
  • Integrate source control into your DevOps without losing quality and performance
  • Ensure smooth and flexible change management in a visual and user-friendly interface
  • Adjust a database development and deployment due to the support of shared and dedicated database development models
  • View a complete revision history of a database or database objects
dbForge Source Control for SQL Server