Subversion Quick Guide

Source: Internet
Author: User

As a new generation version control system contributed by the open-source community, subversion (SVN) has been widely used. I have used CVS (concurent version system, the predecessor of SVN) and Microsoft VSS (visual sourcesafe). In contrast, SVN has more powerful functions and simpler operation features.

Some articles on the Internet have introduced the installation and use of SVN, but I still encountered several problems during the first configuration. Here, I will explain it based on my own ideas, in order to help those who use SVN for the first time and have doubts about some problems.

1. SVN Introduction

If SVN is good, what advantages does SVN have? The SVN Manual provides detailed descriptions. The following describes several important aspects:

1) directory-based version control

The traditional CVs or VSS version control is based on a single file, which does not actually meet the actual needs, because in actual application, we all want to manage by project or project, for example, if we want to extract the entire project file from a historical point in time, the file-based version control system has drawbacks and can only process a single file. SVN can easily achieve this. you can retrieve any file or any historical version of any directory at will.

SVN also allows you to add, delete, copy, and rename files and directories, all of which are recorded in historical information for real version control.

2) Atomic commit

Each operation in SVN is atomic, either all succeeded or all failed. Assume that you want to submit multiple files. If one file conflict exists, other modifications will not be submitted.

3) Efficient branching and tagging Functions

Let's talk about the tag function. In general, a tag is a snapshot at a certain point in time. We can create a tag when the project reaches an important milestone, in this way, you can retrieve these historical versions at any time. I think you may have a question: Isn't SVN a function to retrieve any historical version at will? Yes, labels are mainly used to give friendly names to specific historical versions for ease of use and maintenance.

A branch is used to create multiple parallel working lines. For example, when a project needs to provide some special functions for a user, a branch can be created for it, this ensures the sharing of most codes and makes the entire project easy to maintain and manage.

SVN implements the same branch and label implementation and adopts a mechanism similar to hard-link in Unix/Linux. That is to say, when we create a branch or label, SVN does not immediately create a copy for it, but creates a link. Only when these files are modified later will a copy be generated. This "Slow copy" method is a common optimization method that can effectively save space.

What is the difference between the Branch and the label? The difference lies only in its definition of "Convention as vulgar". Tag means that you will not modify it, and branch means that you will develop it.

4) Multiple Access methods

SVN provides an abstract network access layer that can be accessed through different protocols. First, SVN provides a custom SVN protocol access method, which can be used through a URL such as SVN: // host/Repository. In addition, SVN also provides functions integrated with the Apache web server, so that we can access SVN through http: // host/Repository.

5) binary file support

CVS also supports binary files, but the implementation is not complete. You may have encountered a situation where a text file contains Chinese characters and is considered a binary file, SVN provides comprehensive support for binary files, so that non-text files can be well controlled in the same way as text files.

6) Client integrated with resource manager in Windows: tortoisesvn

SVN only provides command line operations. tortoisesvn is a graphical interface developed by a third party. Its appearance makes version management in Windows very convenient. However, because it is embedded in the resource manager, it may affect the system speed-very small, you can evaluate it yourself.

7) platform independence

SVN adheres to the consistent advantages of open-source software. Both Windows and Linux platforms can access the svn server.

If you were a VSS user in the past, you should also mention that, unlike VSS, SVN has a different idea. vss puts version conflict control before the operation, to operate a project, you must first execute checkout to lock the project and prevent others from modifying it at the same time. SVN provides the same lock function, but in general, we only need to modify the lock independently without locking the project. If there is a conflict, we can process it when submitting it. That is to say, SVN puts the conflict control after the operation and when it is submitted. You may think VSS is more reasonable, but the actual situation is the opposite, because in our actual use, someone often forgets to checkin after checkout the entire project, or if you do not select recursive, you forget to checkin the file in the subdirectory. This makes it difficult for others to modify the file, so you have to notify them manually, which is very troublesome.

2. SVN server Construction

This section is intended for administrators. Common users can skip this section. I only use Windows as an example here. Linux can be installed in a similar way (some configuration parameters may vary. For details, refer to the help manual ).

1) install the svn Server

A. Download

The official SVN website is http://subversion.tigris.org/and the latest version is 1.4.2. The binary installation package in Windows is divided into two types: one is the installation file ending with setup and the other is a common compressed package file. The setup file automatically registers some information, for example, environment variables and services can be implemented manually. When I write this article, the official website only has common binary files. It is estimated that the setup file will come out later. Note: When downloading the software, read the precautions in detail and check the software version to avoid any problems.

The selected region is svn-win32-1.4.2.zip.

B. Installation

Decompress svn-win32-1.4.2.zip to the installation directory. I chose C:/program files/subversion. If it is a setup file, run the installation file directly. For the compressed package, we can add the bin path to the system environment variable for convenient operations. The bin directory contains the following files:

Svnadmin: A warehouse management tool, including creation, repair, and backup.
Svnlook: the warehouse viewing tool, including information, logs, and lock status, without any changes to the warehouse.
Svnserve: SVN service program that allows access to the repository through the svn network protocol.
SVN: SVN client, used to access the repository and manage the project version.
Svnversion: a client tool used to view the revision information of a local copy.

C. Create a repository)

SVN uses a repository as the Version Control Unit. a svn server can manage multiple repositories. Each repository has an independent revision number (revision ), any update in the repository will increase the revision number. You can choose to create one or more repositories as needed. Here, I will create multiple repositories as an example. Suppose we put all the Repositories under the D:/svn_repos directory, the following command creates a test repository in this directory:

Svnadmin create d:/svn_repos/test

If it is successfully created, a test directory will be added under D:/svn_repos.

2) set up svnserve access

SVN and HTTP are two parallel access methods, either of which can be used or both.

A. register the service

To enable the svn service program to run automatically after each startup, We need to register it as a service. Run the following command on the console:

SC create svnservice binpath = "/" C:/program files/subversion/bin/svnserve.exe/"-- service-R D:/svn_repos" Start = auto

Note that the preceding commands are in one line. SC .exe is a tool that comes with Windows 2000 and later. It is not available in Windows 2000. It can be copied from XP. Svnservice is the service name, and the format of parameters following it is strictly required. There is no space before the equal sign and there is later. The binpath contains multiple parameters, so it is enclosed in quotation marks. Because there are spaces in the path, a quotation mark is added. --Serviceand -rare both parameters of svnserve.exe. The former requires it to run as a service, and the latter specifies the root path of the Repository (multiple repositories are the parent directory of the repository ).

SVN with the installation package automatically registers the service. You may need to modify the-R parameter by running the following command:

SC config svnservice binpath = "/" C:/program files/subversion/bin/svnserve.exe/"-- service-R D:/svn_repos"

B. Access

After registration, run SC start svnservice or service manager (service. MSC) to start the service.
Next, we can use the following command to test whether the system works properly:

SVN info SVN: // localhost/test

If the relevant information of the warehouse is correctly displayed, this is done. Otherwise, check whether the service parameters are correctly configured. For example, if the correct-R value is not specified in the service parameters, the following error is returned:

No repository found in 'svn: // localhost/Test'

If tortoisesvn is installed, you can directly input SVN: // localhost/test in the browser to bring up tortoisesvn's repos-browser. At this point, you can use tortoisesvn to import the project for version management (see the following article ).

C. Permission Configuration

All users can perform any operation before permission configuration, which is not allowed in many cases. When creating a repository, Several folders are generated under the repository directory. The conf file stores configuration information, including three files:

Authz: access permission Configuration
Passwd: user name and password configuration
Svnserve. conf: basic configuration information

Configure svnserve. conf first, and remove the comments before the configuration items. The final content is as follows:

[General]
Anon-access = read
Auth-access = write
Password-DB = passwd
Authz-DB = authz

The meanings of these parameters are described in detail. Anon-access and Auth-access are respectively used to control access to anonymous users and authenticated users, password-DB indicates the path of the user's password file, and authz-DB indicates the path of the permission configuration file. Another parameter, realm, is used to specify the authentication domain to which the warehouse belongs. By default, each warehouse is located in a different domain (each warehouse has a unique UUID). Therefore, we can leave this item unspecified, unless multiple repositories need to share the same passwd configuration.

The configuration of the passwd file is simple. The format is as follows (username and password are used before the equal sign ):

[Users]
Harry = 123
Sally = 1, 123
Guest= 123

Authz allows you to create a user group and precisely configure the access permissions of a user or user group on a file or directory. The following is an example:

[Groups]
Harry_and_sally = Harry, Sally

 

[/]
* = R

[/Project1]
* =
Harry = RW
Sally = r

[/Project1/Foo]
Sally =

[/Project2]
@ Harry_and_sally = RW
Guest = r

The file content is actually easy to understand. Groups is used to define user groups, followed by specific resource access control./indicates the root directory of the Repository. * indicates all users. The @ symbol must be added before the user group, r indicates readable, W indicates writeable, and empty on the right of the equal sign indicates no permission. NOTE: For the directory structure, when a user accesses a resource, SVN will first check whether there is access control for the resource directly. If not found, it will inherit the access permission of the upper-level directory, so it is recursive.

When we have multiple warehouses, we will find that the user accounts of these warehouses are the same in most cases. Therefore, we can put the passwd file in a public place, then, point the password-DB configuration of all repositories to the file. Correspondingly, authz-dB can also share a file, but you need to specify the repository When configuring specific access control, as shown below:

[/]
* = R

 

[Repos1:/project1]
* = R
Harry = RW

[Repos2:/project1]
* = R
Sally = RW

The preceding configuration indicates that everyone has the read permission on the root directory of all repositories, but only Harry has the read and write permission on Project 1 in repository repos1, only Sally has read and write permissions on project1 in the repository repos2.

3) set up an HTTP access method

SVN can implement web access through Apache, but this is not necessary unless you have this requirement.

A) download

The official Apache website is invalid this is not an Apache module DSO "error.

The version I downloaded is apache_2.0.59-win32-x86-no_ssl.msi

B) Installation and Registration

Run the Apache installation program. Because version 2.0 is not automatically registered as a service, we need to handle it manually. Run cmd.exe, go to the bin folder under the Apache installation directory, and run the following command:

Apache-K install

You can view more commands through Apache help.

After registration, you can start the service through the Apache monitor in the system tray. If port 80 is not in use, the server should be started normally. The Apache test page is displayed through http: // 127.0.0.1.

C) Configuration

Apache is configured through the httpd. conf file in the conf directory. For example, the default listening port is 80, search for listen 80 in the file, and change 80 to another port you need. After configuration, you must restart Apache to take effect. For more information about Apache configuration, see its help manual or Google. The following is a Chinese version of the help manual.

To enable Apache to support SVN, such as adding some configuration items, a typical configuration is as follows:

# Load the mod_dav module. It supports the WebDAV (web-based Distributed Authoring and Versioning) Protocol and is provided by Apache.
Loadmodule dav_module modules/mod_dav.so

# Load the mod_dav_svn module, which communicates with mod_dav, so that Apache supports SVN, which is located in the bin directory of SVN.
Loadmodule dav_svn_module "D:/program files/subversion/bin/mod_dav_svn.so"

# Load the mod_authz_svn module for permission management
Loadmodule authz_svn_module "D:/program files/subversion/bin/mod_authz_svn.so"

# Configure SVN access paths and Related Parameters
<Location/SVN/> # access the svn server through http: // host/SVN/
Dav SVN # required
Svnparentpath D:/svn_repos # description D:/svn_repos.
Svnlistparentpath on # list all Repositories under D:/svn_repos on the webpage

Authtype basic # basic username and password authentication method
Authname "SVN repos" # Authentication Name for prompt use
Authuserfile D:/svn_repos/users # user name and password file
Authzsvnaccessfile D:/svn_repos/authz # permission Control File

Require valid-user # webpage access only after authentication
</Location>

# Redirection, used to redirect the http: // host/SVN address to http: // host/SVN/
Redirectmatch ^ (/SVN) $1/

The following are some important points:

I. many articles on the Internet mentioned that the mod_dav_svn.so and mod_authz_svn.so files are directly copied to the modules directory of Apache. When I used this method, the apache service cannot be started on a Windows 2000 Server, so it took a long time. Later, I realized that these module files are actually some dynamic link libraries, which need to depend on several other DLL files under the bin directory of SVN (you can change the suffix to DLL, then view the dependencies through the depends with VC). Therefore, if no environment variable is set, Apache will fail to load these modules, of course, you can copy all the dependent files (mainly libdb43.dll. In fact, we only need to reference these modules through the absolute path, so that the svn upgrade does not need to be copied again.

II. The URL access path is/SVN/instead of/SVN. because the latter may be faulty, the following error message may occur during http: // host/SVN access.

Iii. svnparentpath is used when multiple warehouses exist. If only one warehouse exists, you can directly use svnpath to specify the warehouse path.

IV. authuserfile indicates the user name and password file, but it is not the same as the passwd file in the svn repository mentioned earlier. authuserfile is the Apache authentication file format, the main difference between the two is that the user name and password are different, passwd is an equal sign, and users here is a colon, at the beginning, I used them as a file, which made the client inaccessible (Why didn't SVN define the passwd format as the same as that of authuserfile? In this way, the two can share a file ). To encrypt the password, the users file must be generated using the htpasswd tool attached to Apache. In fact, we can also directly use the plaintext method.

V. The permission control file authzsvnaccessfile is the same as the authz file in SVN, so it can be shared.

4) other management functions

A. Backup

B. Repair

3. SVN client usage

This section describes common operations for client users.

1) Client installation

The client can use the command line method or tortoisesvn graphical method. I personally think the latter is more convenient.

Tortoisesvn is obtained from http://tortoisesvn.tigris.org/and should be consistent with the server. If the command line is used, download a svntwo package from http://subversion.tigris.org.

Tortoisesvn is a graphical client software. In fact, the svn installation package contains a client program, which is just a command line method. You can choose whether to install it as needed. The official website of tortoisesvn is http://tortoisesvn.tigris.org/. in the same example, select the region with the svnserver.

The version I use here is the TortoiseSVN-1.4.0.7501-win32-svn-1.4.0.msi

After the installation is complete, you will be prompted to restart the machine. In fact, you can directly use it without restarting the machine, but the svn file icon will be updated after the restart. Is the right-click menu content of the svn Workspace:

2) Main Operations

Tortoisesvn is easy to use, and all operations are completed by right-clicking the menu. The command content is also intuitive, and there is a very detailed help manual, here is a brief introduction.

A) import a project (import)

First, sort out the projects (directories) that require version management and remove unnecessary files, such as temporary files generated by the compiler. Right-click the top-level folder, select tortoisesvn-> Import..., enter the path of the svn server to be stored, and click OK. In this way, the local project is imported to the server.

Command Line: SVN import [path] URL

B) Check out the project (checkout)

After the project is successfully imported for the first time, the local content is useless. We need to create a new workspace and download the controlled project file from the svn server again, run "tortoisesvn-> checkout... ", select or enter the project URL, and click OK. All future work should be done in this workspace.

By default, the latest version of the project (head) is obtained. To obtain a previous version, specify the corresponding revision number (revision.

Command Line: SVN checkout URL [@ rev]... [path]

C. Update and commit)

If someone else modifies the project, we need to download the latest version from the server, which is implemented through the "SVN Update" right-click menu.

Command Line: SVN update [path...]

If the modification is made locally, update the modification to the server in time, which is implemented through "SVN commit. A good habit is that you should specify the modification content for each submission to facilitate future verification.

Command Line: SVN commit [path...]

D) add and delete files)

To add a new file or folder to a controlled project, you only need to perform the "tortoisesvn-> Add" Operation on the target. Note: This is only added locally. to submit it to the server, you must execute commit.

Command Line: SVN add path...

Similarly, to delete a controlled file or folder, you only need to perform the "tortoisesvn-> Delete" operation.

Command Line: SVN Delete path/URL...

Tortoisesvn also provides a RENAME operation "tortoisesvn-> rename", which is actually a combination of adding and deleting.

E) Revert)

Sometimes, we may modify, add, or delete errors. If not submitted, we can use the tortoisesvn-> revert command to cancel all local changes.

Command Line: SVN revert path...

F) view information

SVN provides several ways to view information. Show log is used to display the log information of each version change. repo-brower is a repository browser, similar to the resource manager, revision graph visually displays version changes, especially for branch and tag management.

3) Other operations

A) Conflict Resolution (resolved)

If we modify the modification locally and someone else submits the modification to the server, a conflict may occur when we execute update ). Resolved does not resolve conflicts. Instead, it does not merge any changes made by others, allowing us to submit our version to the server.

In short, revent revokes local modifications while resolved retains local modifications.

B) cleanup)

If an exception occurs when executing a command, for example, the server suddenly fails, the local work zone will be in an abnormal state. Cleanup can be used to clear this state so that the work zone will not be affected.

C. Get lock and release lock)

Conflicts occur because different developers modify the same file at the same time. To avoid this problem, we can forcibly lock the content we want to modify, in this way, no one else can submit the modification before we unlock it.

D) branch and label (branch/Tag)

In the beginning of this article, we have explained that the purpose of the branch is to create a parallel working line, and the function of the label is to save the snapshot of a certain version of the project. The two are implemented in the same way. They are all executed through the branch/Tag command.

E) Export (Export)

To implement version management, SVN generates a hidden directory in each directory of the workspace. SVN folder, but sometimes we want to get a clean one. the project structure of the svn folder, such as the export function, can be used when software is released.

F) relocate)

Sometimes, the IP address of the svn server may change. If this happens, will each of us download the local workspace again? No, you only need to reconfigure the server address corresponding to the local work zone through relocate.

G) Patch Management)

Do not be confused by the patch name. In fact, it is not in the scope of SVN version management. Here the so-called patch refers to the modifications made by those who do not have the write permission (COMMIT) to the project, which are generated by "tortoisesvn-> Create patch, then they send the patch to the Project Administrator by email. The Administrator executes "tortoisesvn-> apply patch" and confirms the modification before submitting the patch. This function is mainly used to manage open-source projects.

4. FAQs

1) What directory structure should be used for repository?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.