Subversion (SVN) is an open source version control system that allows you to look at previous file versions and track their changes over time. You can use SVN to create branches to work on multiple versions of your files or data. This topic describes how to deploy and use SVN.
SVN
The data that SVN manages is stored in a repository. It maintains a complete history of every change ever made to your files. You can roll back to a previous version or retrieve the change history of files from the repository. The following terms or operations are commonly used in SVN:
Repository: stores source code.
Checkout: checks out source code from the repository to create a working copy on your on-premises device.
Commit: commits modified code to the repository.
Update: synchronizes source code from the repository to a working copy on your on-premises device.
Preparations
Create an Elastic Compute Service (ECS) instance. For more information, see Create an instance on the Custom Launch tab.
Make sure that the ECS instance meets the following requirements:
The instance is associated with a static public IP address (also called auto-assigned or system-assigned public IP address) or an elastic IP address (EIP). For information about how to associate an EIP with an instance, see Associate or disassociate an EIP.
The instance runs an Alibaba Cloud Linux 3, Alibaba Cloud Linux 2, or CentOS 7.x operating system.
The instance type of the instance meets the requirements for deploying SVN. Select an instance type during instance creation based on your project scale and your team size. We recommend that you use an instance type with four or more vCPUs and 4 GiB or more of memory.
An inbound rule is added to a security group of the instance to allow traffic on ports 22, 80, and 443. For information about how to add an inbound security group rule, see Add a security group rule.
NoteIf you want to access SVN by using svnserve, add an inbound security group rule to open port 3690.
SVN access methods
You can access SVN over HTTP or by using svnserve based on your business requirements. The following table describes the differences between the access methods.
Item | SVN access over HTTP | SVN access by using svnserve |
Protocol | HTTP. | Custom SVN protocol. |
Access mode | Web browsers or clients. | Only clients. |
Port | Port 80. | Port 3690. |
Security | HTTPS for encrypted communication. | Plaintext communication by default. You can complete encryption settings to encrypt communication. |
Configuration | Configurations on the web server. | Configurations on the SVN server. |
Feature | More features, such as access control and log query. | Fewer and simpler features. |
Deploy SVN with HTTP access
Step 1: Install SVN
Connect to the Linux instance on which you want to install SVN.
For more information, see Connect to a Linux instance by using a password or key.
Run the following command to install SVN:
sudo yum install -y subversion
Run the following command to check the SVN version:
svnserve --version
The following command output indicates that SVN is installed.
Step 2: Install the Apache HTTP Server (httpd)
Run the following command to install httpd:
sudo yum install httpd -y
Run the following command to check the httpd version:
httpd -version
The following command output indicates that httpd is installed.
Step 3: Install mod_dav_svn
mod_dav_svn is an Apache HTTP Server (httpd) module that provides web access to SVN.
Run the following command to install mod_dav_svn:
sudo yum install mod_dav_svn -y
Step 4: Configure SVN
Run the following commands in sequence to create an SVN repository:
sudo mkdir /var/svn cd /var/svn sudo svnadmin create /var/svn/svnrepos
Run the following command to change the user group of the SVN repository to apache:
sudo chown -R apache:apache /var/svn/svnrepos
Run the following commands in sequence to check the files that are automatically generated in the SVN repository:
cd svnrepos ls
The following table describes the SVN directories and files.
Directory or file
Description
db
The directory that stores version-control data files.
hooks
The directory that stores hook scripts.
locks
The directory that stores the SVN repository lock files and can be used to track accesses to the repository.
format
The text file that contains a single integer value, which indicates the version number of the SVN repository.
conf
The SVN repository configuration file that stores the usernames and access permissions of the repository.
Set a username and a password for the SVN repository.
Passwords for SVN are stored in plaintext, but HTTP does not support plaintext passwords. Therefore, you need to create a separate file named passwd. In this example, the username is
userTest
and the password ispassWDTest
. Run one of the following commands to create the passwd file.The first time that you add a user for the SVN repository, run the following command with the
-c
parameter to create the passwd file:sudo htpasswd -c /var/svn/svnrepos/conf/passwd userTest
If this is not the first time that you add a user for the SVN repository, run the following command to create the passwd file:
sudo htpasswd /var/svn/svnrepos/conf/passwd userTest
Configure the password of the user as prompted.
Run the following command to go to the conf directory:
cd /var/svn/svnrepos/conf/
Configure the read and write permissions for the user.
Run the following command to open the access control file:
sudo vim authz
Press the
I
key to enter Insert mode.Move the pointer over the end of the file and add the following code to grant the read (r) and write (w) permissions to the user (userTest):
[/] userTest=rw
Press the
Esc
key to exit Insert mode, enter:wq
, and then enter the Enter key to save and close the file.
Modify the configurations of SVN.
Run the following command to open the configuration file of SVN:
sudo vim svnserve.conf
Press the
I
key to enter Insert mode.Move the pointer over the following lines and delete the number sign (#) and spaces from the beginning of each line.
NoteLines cannot start with spaces. A space is required before and after each equal sign (=).
anon-access = read auth-access = write password-db = passwd authz-db = authz realm = /var/svn/svnrepos
Press the
Esc
key to exit Insert mode, enter:wq
, and then enter the Enter key to save and close the file.
Start the SVN repository.
Run the following command that includes the absolute path to the SVN repository to start the repository:
sudo svnserve -d -r /var/svn/svnrepos/
NoteYou can run the
killall svnserve
command to stop the SVN service.Run the following command to check whether the SVN service is started:
ps -ef |grep svn
The following command output indicates that the SVN service is started.
Step 5: Configure Apache
Run the following command to add and edit the httpd configuration file:
sudo vim /etc/httpd/conf.d/subversion.conf
Press the
I
key to enter Insert mode.Add the following information to the
subversion.conf
file:<Location /svn> DAV svn SVNParentPath /var/svn AuthType Basic AuthName "Authorization SVN" AuthzSVNAccessFile /var/svn/svnrepos/conf/authz AuthUserFile /var/svn/svnrepos/conf/passwd Require valid-user </Location>
Press the
Esc
key to exit Insert mode, enter:wq
, and then enter the Enter key to save and close the file.Run the following command to start the httpd service:
sudo systemctl start httpd.service
Deploy SVN with svnserve-based access
Step 1: Install SVN
Connect to the Linux instance on which you want to install SVN.
For more information, see Connect to a Linux instance by using a password or key.
Run the following command to install SVN:
sudo yum install -y subversion
Run the following command to check the SVN version:
svnserve --version
The following command output indicates that SVN is installed.
Step 2: Configure SVN
Run the following commands in sequence to create an SVN repository:
sudo mkdir /var/svn cd /var/svn sudo svnadmin create /var/svn/svnrepos
Run the following commands in sequence to check the files that are automatically generated in the SVN repository:
cd svnrepos ls
The following table describes the SVN directories and files.
Directory or file
Description
db
The directory that stores version-control data files.
hooks
The directory that stores hook scripts.
locks
The directory that stores the SVN repository lock files and can be used to track accesses to the repository.
format
The text file that contains a single integer value, which indicates the version number of the SVN repository.
conf
The SVN repository configuration file that stores the usernames and access permissions of the repository.
Set a username and a password for the SVN repository.
Run the following commands to open the user configuration file:
cd conf/ sudo vim passwd
Press the
I
key to enter Insert mode.Move the pointer over
[users]
and add a username and a password.NoteSet the username and password in the following format: username = password. Example: userTest = passWDTest, as shown in the following figure. A space is required before and after the equal sign (=).
Press the
Esc
key to exit Insert mode, enter:wq
, and then enter the Enter key to save and close the file.
Configure the read and write permissions for the user.
Run the following command to open the access control file:
sudo vim authz
Press the
I
key to enter Insert mode.Move the pointer over the end of the file and add the following code to grant the read (r) and write (w) permissions to the user (userTest):
[/] userTest=rw
Press the
Esc
key to exit Insert mode, enter:wq
, and then enter the Enter key to save and close the file.
Modify the configurations of SVN.
Run the following command to open the configuration file of SVN:
sudo vim svnserve.conf
Press the
I
key to enter Insert mode.Move the pointer over the following lines and delete the number sign (#) and spaces from the beginning of each line.
NoteLines cannot start with spaces. A space is required before and after each equal sign (=).
anon-access = read auth-access = write password-db = passwd authz-db = authz realm = /var/svn/svnrepos
Press the
Esc
key to exit Insert mode, enter:wq
, and then enter the Enter key to save and close the file.
Start the SVN repository.
Run the following command that includes the absolute path to the SVN repository to start the repository:
sudo svnserve -d -r /var/svn/svnrepos/
NoteYou can run the
killall svnserve
command to stop the SVN service.Run the following command to check whether the SVN service is started:
ps -ef |grep svn
The following command output indicates that the SVN service is started.
Use SVN
This section describes the steps to manage code in SVN:
Checkout: Check out source code to create a working copy on your on-premises device.
Others modify the source code and commit the modifications to the repository.
Update: Obtain the latest version of the source code from the repository.
Change and debug the source code.
Commit: Commit the modified source code to the repository. Other users can view your modifications.
Checkout: Check out source code to create an on-premises working copy
Download and install the TortoiseSVN client on your on-premises Windows device.
Right-click a blank area in the on-premises project folder.
In this example, the project folder is
C:\Test
.Select SVN Checkout...
Configure the following parameters and click OK:
URL of repository: Enter the URL of the SVN repository.
If you access SVN over HTTP, enter the URL of the SVN repository in the following format:
http://<Public IP address of the ECS instance>/svn/<SVN repository name>
.If you access SVN by using svnserve, enter the URL of the SVN repository in the following format:
svn://<Public IP address of the ECS instance>/
.NoteWhen you start SVN from the parent directory of the SVN repository, the URL from which to check out source code must include the name of the SVN repository.
Checkout directory: Specify an on-premises directory in which to check out source code to create a working copy. In this example, the on-premises directory is
C:\Test
.
NoteThe first time you log on to SVN, enter the username and password that you configured in the passwd file.
The following message indicates that the checkout operation is complete.
Update: Obtain the latest version of the source code from the repository
After a project is updated in the SVN repository, you can right-click a blank area in the on-premises project folder, and then select SVN Update to pull all modifications to the project from the repository and download the latest version of the project.
When you right-click a blank area in the on-premises project folder and select SVN Update, all files in the project folder are overwritten. To prevent content loss caused by the overwrite process, we recommend that you back up the original content in the project folder before performing the update operation.
Commit: Commit the modified source code to the repository
To commit on-premises modifications to the repository, perform the following steps:
Right-click a blank area in the on-premises project folder and then select SVN Commit...
Enter a commit message, select the objects that you want to commit, and then click OK.
The changes that you make on premises to the project are committed to the SVN repository and applied to the project in the repository.
NoteA conflict occurs if you attempt to commit a file that already has a newer repository version. Your commit fails. To resolve the issue, back up your on-premises project, check out the latest project files from the SVN repository, change the latest project files on premises, and then commit the changed project files to the repository.
If a file is deleted from the project that you commit, the message shown in the following figure appears, indicating that the file is missing.
Restore a deleted file
After you delete a file, you can restore the file in SVN.
Open the on-premises project folder, right-click a blank area in the folder, and then select SVN Checkout... to check out the latest version of the project.
Delete a file.
Use one of the following methods to restore the deleted file based on whether you commit the delete operation to the SVN repository:
If the delete operation is not committed, right-click a blank area in the on-premises project folder and choose
If the delete operation is committed, the change is synchronized to the repository and the file is deleted from the repository. Perform the following steps to restore the deleted file:
Right-click a blank area and choose
to view operation logs.In the logs, click the deletion log entry for the deleted file. The information about the deleted file is displayed.
Right-click the deleted file and select Save revision to...
In the Save revision to... dialog box, enter a file name and click Save to save the file to the directory from which the file was deleted.
Open the on-premises project folder, right-click a blank area in the folder, and then select SVN Commit... The on-premises project data is synchronized to the SVN repository.
FAQ
Why does an error message indicating that the host does not respond appear when TortoiseSVN is used to access the SVN server?
Cause:
The SVN server is not started.
The ports required by the SVN server are not opened in the related security group.
The firewalld service is started for the ECS instance, but traffic on the ports required by the SVN server is not allowed.
Solution:
Check the status of SVN.
ps -ef |grep svn
The command output shown in the following figure indicates that the SVN service is started. If the following command output is not returned, run the
sudo svnserve -d -r /var/svn/svnrepos/
command to start SVN.Check whether the rule of the security group to which the ECS instance belongs meet the requirements of the SVN server.
SVN access over HTTP: Ports 22, 80, and 443 must be opened.
SVN access by using svnserve: Ports 22, 80, 443, and 3690 must be opened.
Query the firewalld service.
Query the status of the firewalld service.
sudo firewall-cmd --state
If the firewalld service is in the
not running
state, the firewalld service is not started and has no impacts on the SVN server.If the firewalld service is in the
running
state, the firewalld service is started. Perform the next step.
Open ports such as port 3690 in the firewalld rule for SVN.
sudo firewall-cmd --add-port=3690/tcp --per
Reload the
firewalld
service configuration to make the modification take effect.sudo systemctl reload firewalld