[SVN] Build a code version controller (SVN)

Table of contents

foreword

1. What is SVN?

2. Use steps

1. Install SVN on CentOS

2. The server creates a directory

3. Start the service

4. View the running port

5. Create a code base

6. Modify code base properties (svnserve.conf)

6. Specify permissions (authz)

7. Specify the user login password (passwd)

8. Computer client, etc. to access version library


foreword

        As a developer, after the function is completed, hand it over to Party A. Party A thinks that your page is too simple and needs to be modified. Then you work overtime and make major changes. The page becomes very rich. It's all bells and whistles, no, let's use the first version. Now that the code has been completely changed by you, you need to get back the first version of the program. At this time, you have to work overtime to change the modified code back.

        But if you have a code version of the controller, and submit it as a version every time a function is changed, then no matter which version Party A wants to go back to, you can go back to that version immediately.

        Basically, all companies now establish a historical version controller for internal documents or codes, and all modification records will be kept in the code base of the server. Currently, common code version controllers on the market include SVN and GIT. Of course, SVN is not limited to establishing a version controller, but also allows project team members to carry out collaborative development. For example, A develops a function of uploading files, and B develops a function of downloading files. Both can be developed at the same time, and then uploaded to the version library respectively. do not affect each other. But if the two modify the same line in the same file, there will be a conflict, and how to modify and resolve the conflict will be explained later.


1. What is SVN?

        Subversion (SVN) is an open source version control system, which means that Subversion manages data that changes over time. These data are placed in a central repository (repository). This repository is much like a normal file server, but it remembers every file change. In this way, you can restore the file to an old version, or browse the change history of the file.

        SVN first needs a code warehouse. After you have a code warehouse, you can create a local copy anywhere you can access it. For example, if you build a code library on the cloud server of a major manufacturer, after you purchase the cloud service, the manufacturer will give you a public IP, and you can access the cloud you purchased through this public IP in any place with a network. The server can also get the code in your code warehouse. But if you are building a code repository on a LAN server, you can only get the code repository after connecting to the LAN first.

         Last year, it happened that Alibaba Cloud was doing a promotional activity, and then I went to collect some cashmere. By receiving benefits for newcomers , it cost less than 200 yuan to buy a shared S6 for one year. It is very cost-effective for newcomers to receive benefits in the first year to buy servers. , It will be much cheaper than building a local server by yourself, and it will be calculated according to the electricity bill. The local server has 1 kilowatt-hour of electricity a day, 1 yuan for 1 kilowatt-hour of electricity, and 365 yuan for 365 days. This does not include broadband fees, etc., so newcomers Don't worry about the 200 or 300 yuan, go boldly to squeeze the wool, of course, you can also squeeze the wool from Tencent Cloud- New Year 618 special event .


2. Use steps

1. Install SVN on CentOS

1) Check whether svn is installed

rpm -aq subversion

2) Command to install svn

yum -y install subversion

2. The server creates a directory

mkdir svn
cd svn
mkdir svndata

3. Start the service

 svnserve -d -r /home/svn/svndata/

The -d parameter makes svnserve run in the background.

The -r parameter defines the data warehouse, the address that can be accessed on the network, and specifies the root location of the file system (the root directory of the repository)

4. View the running port

netstat-lntup 

Generally the default is 3690

 Remember to release this port on the firewall, otherwise the external network cannot be accessed.

 If you find that there is a problem with SVN and you need to stop the service, you must first check which PID the service is, and modify the red part to be the PID of the corresponding SVN service

ps -ef|grep svn

killall -9 377686

5. Create a code base

svnadmin create /home/svn/svndata/test

6. Modify code base properties (svnserve.conf)

cd /home/svn/svndata/test/

cd conf/

vi svnserve.conf

Commonly used configurations include access rights, authentication, passwords, etc. Generally, the red part does not change the path, just delete the # in front

anon-access = none

auth-access = write

password-db = /home/svn/svndata/test/conf/passwd

authz-db = /home/svn/svndata/test/conf/authz

  • anon-access:  Control the permission of users not added by authz to access the repository, and the value range is "write", "read" and "none". That is, "write" means readable and writable, "read" means read-only, "none" means no access permission, default value: read.

  • auth-access:  Control the permissions of users added in authz to access the repository. The value ranges are "write", "read" and "none". That is, "write" means readable and writable, "read" means read-only, "none" means no access permission, default value: write.

  • authz-db:  Specifies the name of the authority configuration file through which path-based access control can be implemented. Unless an absolute path is specified, the file location is a relative path to the conf directory, default: authz.

  • authz-db:  Specifies the name of the authority configuration file through which path-based access control can be implemented. Unless an absolute path is specified, the file location is a relative path to the conf directory, default: authz.

  • passwd-db: Specify the authentication password file name for auth to add users to access the repository.

6. Specify permissions (authz)

[groups]

Used to configure accessible users, the configuration format is as follows

<usergroup> = <userlist>

If you do not specify the access path, you can control all paths. If you need to configure different access paths for different user groups, such as /foo/bar,

[/foo/bar]
xanadw = rw

configuration format

[<repository name>:<path>]

[test:/]
xanadw = rw

auth common configuration, root directory permissions are used:/

[groups]
xanadw = xanadw

[test:/]
xanadw = rw

7. Specify the user login password (passwd)

 The front is the user, and the back is the password.

8. Computer client, etc. to access version library

For local access, you need to download the TortoiseSVN software, then create a directory, and press the right mouse button

 Enter url, //followed by the public network IP

 

1) After the user authentication is completed, you can use SVN to check out and export the version library.

2) After checking out, you can submit, upload, update and other operations.

If you add a new file, you must use the right button, svn--add operation to add this file to the version control, and it will be displayed when you submit it.

3) Submit operation

If you need to submit the modification to the version library, you only need to right-click in the blank space of the folder and click SVN to submit.

Then when submitting, you can write some comments below, fill in the modified content, and restore it later.

This completes the submission.

The version browser can also view your files.

  If the file has been modified it will be displayed! icon, and a green tick if it is consistent with the server version library.

3) Restore files

If a file is modified incorrectly, just right-click to display the log.

 The current version will be displayed in bold and black. Then select the version you want to restore and click Revert to this version.

 Please note that this restore operation will only change the changes you submitted on the server, and the locally modified content will not be restored by clicking the restore operation.

4) Cleanup (restore local modification, use this function carefully, you can submit or save a copy locally before cleaning )

All uncommitted local changes will be cleared.


 Summarize

        This article mainly introduces how to use the cloud server to build a code version controller. One of the advantages of using the cloud server is that no matter whose computer you are using, as long as you have the Internet, and remember your user name and password, you can copy a code at any time to your local computer. Now most companies are also using the SVN software, so the use of this software is briefly introduced. If there is a conflict in the file, you must manually modify the conflict and then submit it. It is very easy to use for laboratory development projects in colleges and universities. Because you often change directions, you may sometimes not remember the code you wrote before, so use SVN to record all your modifications to prevent you from finding the code.

Guess you like

Origin blog.csdn.net/xanadw/article/details/126075521
svn