[Mountain Notes-Tool Framework] SVN Version Control System

[Mountain Notes-Framework Tool] SVN Version Control System

Learning materials:

1. Download address of the printed version of this article: [Mountain Notes-Framework Tool Notes] SVN Version Control Tool-Printed Version.pdf

2. SVN and TortoiseSVN online Chinese documents: http://svndoc.iusesvn.com/

3. SVN tutorial-rookie tutorial: https://www.runoob.com/svn/svn-tutorial.html

4. SVN Chinese manual download address: svnbook1.4 Chinese manual.pdf

5. TortoiseSVN Chinese document download address: TortoiseSVN-1.9.3-zh_CN Chinese user manual.pdf , TortoiseMerge-1.9.3-zh_CN.pdf

6. TortoiseSVN installation package: TortoiseSVN-1.13.1.28686-x64-svn-1.13.0.msi

7. TortoiseSVN language pack (Chinese): LanguagePack_1.13.1.28686-x64-zh_CN.msi

Highlights of this article:

1. Overview of SVN

2. SVN installation

3. SVN life cycle

4. SVN server operation

5. SVN client operation

6. TortoiseSVN tutorial

1. Overview of SVN

1. Introduction to SVN

(1) SVN is the abbreviation of Apache Subversion and is an open source version control system.

(2) SVN was developed by CollabNet Inc in 2000 and has now developed into a project of the Apache Software Foundation.

(3) SVN manages data (such as code) that changes over time. These data are placed in a central repository (repository). This archive will remember every file change and can restore the file to the old version , Or browse the history of file changes.

(4) The SVN management source code is in units of behavior. As long as the same line of code is not modified, the SVN will automatically merge the two modifications. If it is the same line, SVN will prompt a file conflict (Conflict), which needs to be confirmed manually.

(5) Compared with RCS and CVS, SVN uses a branch management system, and the design goal is to replace CVS.

(6) SVN source code address: https://github.com/apache/subversion

2. Basic concepts of SVN

(1) repository (source code repository): a place where source code is uniformly stored.

(2) Checkout (extract): Create a working copy from the repository to a local directory.

(3) Commit (commit): Submit locally modified code to the repository (repository).

(4) Update: update the local working copy and synchronize with the version library.

3. Main functions of SVN

(1) Directory version control

CVS can only track the history of a single file, but SVN can track changes in the entire directory according to time, and the directory and file can be versioned.

(2) Real version history

Whether it is a file or a directory, you can add (add), delete (delete), copy (copy), and rename (rename) in SVN. All newly added files start from a new, clean version.

(3) Automatic submission

SVN allows one submission, whether single or multiple files are submitted as a whole. Developers are allowed to establish and submit changes in logical intervals to prevent problems when partial submissions are successful.

(4) Metadata included in version control

Each file and directory is attached with a set of attribute keywords and attribute values ​​that can be created, namely Key / Value. Attributes are versioned over time, just like the contents of files.

(5) Select different network layers

  • ① SVN has an abstract concept of file inventory access, and can easily implement new network mechanisms.
  • ② SVN can be embedded in the Apache HTTP server as an extension module.
  • ③ SVN also provides many important functions: such as identity authentication, authorization, online compression, and file library browsing, etc.
  • ④ SVN also has a lightweight independent SVN server, using a custom communication protocol, which can be used in tunnel mode through ssh.

(6) Consistent data processing method

SVN uses a binary difference algorithm to express the difference of files, and stores the files in the archive in a compressed form, and the file differences are transmitted on the network in two directions.

(7) Effective branch and tag

The method of establishing branches and tags in SVN is just to copy the project, and the method used is similar to hard-link.

(8)Hackability

SVN does not have any historical baggage, mainly a group of common C library, with well-defined API, easy to maintain.

4. The advantages of SVN: better than CVS

(1) Atomic submission: Whether a single or multiple files are submitted at one time, they are submitted as a whole.

(2) Rename, copy, delete files and other actions are saved in the version history.

(3) For binary files, a space-saving storage method is used.

(4) The catalog also has a version history. The entire directory tree can be moved or copied, and all version records can be kept.

(5) The cost of branching is very small.

(6) Optimize database access and reduce unnecessary database access.

Two, SVN installation

1. Install SVN under Windows

(1) Download address:

(2) After the download is complete, double-click the downloaded installation file to install, and specify the installation directory of the SVN.

(3) Add environment variables: add the bin directory in the SVN installation directory to the path path.

(4) Enter the svnserve -helpcommand in the CMD command line window to verify whether the installation is successful.

2. Install SVN under CentOS

(1) Most GNU / Linux distribution systems come with SVN, use the svn --versioncommand to check whether it is installed.

(2) If the SVN client is not installed, an error that the svn command cannot be found will be reported.

(3) If the SVN client is installed, the SVN version number and compilation date will be reported.

(4) Installation command:yum install -y subversion

3. Install SVN under Ubuntu

(1) Most GNU / Linux distribution systems come with SVN, use the svn --versioncommand to check whether it is installed.

(2) If the SVN client is not installed, it will report that svn is not installed.

(3) If the SVN client is installed, the SVN version number and compilation date will be reported.

(4) Installation command:apt-get install subversion

3. SVN life cycle

1. Create a repository

(1) The version library is equivalent to a centralized space for storing all the developer's work results code.

(2) The version library can not only store files, but also include the history of each modification, that is, the change history of each file.

(3) Create operation: used to create a new version library.

2. Detection

(1) Checkout operation: used to create a working copy from the repository.

(2) The working copy is the developer's private work space, which can be modified and submitted to the repository.

3. Update

(1) update operation: used to update the version library and synchronize the version library to the working copy.

(2) The repository always keeps the latest code. As soon as the repository is updated, the local working copy will expire.

4. Implementation of changes

(1) Rename operation: You can change the name of the file / directory.

(2) Move operation: used to move files / directories from one place to another in the repository.

(3) Add operation: used to add files / directories, but these added file directories are only added to the list to be changed, and will not become part of the version library until the commit operation is performed.

(4) Delete operation: used to delete the file from the working copy, but the actual deletion of the file is only added to the list to be changed, and the repository will not be deleted until the commit operation is performed.

5. Review the changes

(1) It is a good habit to review the changes made in the working copy before the commit operation.

(2) Status operation: List the changes made in the working copy.

(3) The Status operation only provides a list of changes, but does not provide detailed information about the changes.

(4) Any changes to the working copy will become part of the list to be changed, the Status operation is used to view the list to be changed.

(5) diff operation: used to view detailed information of these changes.

6. Fix errors

(1) Revert operation: resetting the modification to the working copy will destroy the pending list and restore the working copy to its original state.

(2) The Revert operation can reset one or more files / directories, as well as the entire working copy.

7. Resolve conflicts

(1) Merge operation: Automatically handle things that can be safely merged, and others will be treated as conflicts.

(2) Resolve operation: used to help users find conflicts and tell the repository how to deal with these conflicts.

8. Submit changes

(1) Commit operation: used to change from the working copy to the repository.

(2) The Commit operation will modify the contents of the repository. Other developers can view these changes by updating their working copies.

(3) Commit is an atomic operation, either a complete commit is successful, or a rollback fails, and the user will not see half of the successful commit.

(4) Before submission, the file / directory must be added to the list to be changed. The list records the changes that will be submitted.

(5) When submitting, a note is usually provided to explain the change. This comment will also become part of the repository history.

4. SVN server operation

1. Configure the SVN startup mode

(1) New repository directory:mkdir /opt/svn

(2) Create a version library:svnadmin create /opt/svn/svntest

(3) Start the version library:svnserve -d -r 目录--listen-port 端口号

  • ① -r: The configuration method determines the access method of the version library.
  • ② --listen-port: Specify the SVN listening port, without this parameter, the SVN listens to 3690 by default

(4) Single library svnserve mode: -r is directly assigned to the version library

  • ① Command:svnserve -d -r /opt/svn/svntest

  • ② One svnserve can only work for one version library.

  • ③ The configuration of the permissions of the repository in the authz configuration file:

    [groups]
    admin=user1
    dev=user2
    [/]@admin=rw
    user2=r
    
  • ④ URL: Enter svn: //192.168.0.1/ to access the svntest version library

(5) Multi-library svnserve mode: -r is assigned to the superior directory of the version library

  • ① Command:svnserve -d -r /opt/svn

  • ② An svnserve can work for multiple versions.

  • ③ The configuration of the permissions of the repository in the authz configuration file:

    [groups]
    admin=user1
    dev=user2
    [svntest:/]@admin=rw
    user2=r
    [svntest01:/]@admin=rw
    user2=r
    
  • ④ With [/], it means the root directory of all libraries, that is, [/ src] means the src directory under the root directory of all libraries.

  • ⑤ URL: svn: //192.168.0.1/svntest, you can access the svntest version library.

2. Create SVN repository

(1) New repository directory:mkdir /opt/svn

(2) Create a version library:svnadmin create /opt/svn/svntest

(3) Start SVN with multi-library svnserve:, svnserve -d -r /opt/svnURL: svn: //192.168.0.1/svntest01

(4) Configuration directory: / opt / svn / svntest / conf, including svnserve.conf, passwd, and authz configuration files.

(5) SVN service configuration file: svnserve.conf

[general]
anon-access = none
auth-access = write
password-db = /home/svn/passwd
authz-db = /home/svn/authz
realm = tiku
  • ① anon-access: Controls the access rights of non-authenticated users to the version library. The value ranges are write, read and none. That is, write is readable and writable, read is read-only, and none means no access permission. Default value: read

  • ② auth-access: Control the authority of authorized users to access the repository. Default value: write

  • ③ password-db: Specify the user name password file, the default is passwd in the conf directory.

  • ④ authz-db: Specify the rights configuration file to implement path-based access control. Default value: authz

  • ⑤ realm: Specify the authentication domain of the version library, that is, the authentication domain name that is prompted during login.

    • ❶ If the authentication domains of the two repositories are the same, it is recommended to use the same username and password data file.
    • ❷ Default value: UUID (Universal Unique IDentifier, globally unique identification).

(6) User name and password file passwd

  • ① The user name and password file is specified by the password-db configuration item in svnserve.conf, which defaults to passwd in the conf directory.

  • ② The passwd file consists of only one [users] configuration section.

  • ③ [users] configuration section configuration line format: <user name> = <password>

    [users]
    admin = admin
    thinker = 123456
    

(7) Permission profile authz

  • ① The permission configuration file is specified by the authz-db configuration item in svnserve.conf, which defaults to authz in the conf directory.

  • ② The authz configuration file is composed of a [groups] configuration section and several version library path permission sections.

  • ③ The format of the configuration line in the [groups] configuration section is as follows: <user group> = <user list>

  • ④ The format of the segment name of the path permission section of the version library is as follows: [<version library name>: <path>]

    [groups]
    g_admin = admin,thinker
    [admintools:/]
    @g_admin = rw
    * =
    [test:/home/thinker]
    thinker = rw
    * = r
    

Five, SVN client operation

1. SVN checkout operation

(1) Create a version library svntest, URL is svn: //192.168.0.1/svntest, svn user user01 has read and write permissions

(2) Check out the command:svn checkout svn://192.168.0.1/svntest --username=user01

(3) View the command to check out the working copy information:svn info .

2. SVN submit operation

(1) Create a new file in the working copy:echo “Hello,SVN” > HelloSVN.txt

(2) View the status of the working copy:, the svn statusstatus is displayed as? , Indicating that it has not been added to version control.

(3) Added to version control:svn add HelloSVN.txt

(4) View the working copy status:, the svn statusstatus is displayed as A, indicating that it has been added to version control.

(5) Submit to the repository:svn commit -m "SVN readme."

  • ① -m: Remarks the comment information of this submission. If omitted, SVN will open a text editor to allow you to enter the submission information.
  • ② After the command is executed, the submitted file is output, and the revision number is automatically increased by 1.
3. SVN resolves conflicts

(1) Cause of conflict: SVN manages source code in units of lines, as long as it does not modify the same line of code, SVN will automatically merge the two modifications. If it is the same line, SVN will prompt a file conflict (Conflict), which needs to be confirmed manually.

(2) Resolution process: Assuming that the version number of the repository is 10, user A and user B modify the same line in the svntest.txt file at the same time.

  • ① User A first submitted the file that he modified to the version library. After the submission was successful, the version number of the version library was changed to 11.
  • ② When user B submits the file that he modified to the repository, the submission fails and conflicts occur.
  • ③ After user A submits, the version number has changed, user B's working copy has expired, and SVN will not allow user B to submit the modification operation.
  • ④ User B first checks the difference between the modification submitted by user A and his own modification, and executes the svn diffcommand.
  • ⑤ User B needs to update the working copy and execute the svn updatecommand to specify the updated version. The default is the latest version.
  • ⑥ After the working copy and the repository are synchronized, user B can submit his changes to the repository.
4. SVN version rollback

(1) svn revert operation: undo any local changes in files or directories, that is, modification of files.

(2) The specific operation process of undoing file modification:

  • ① Check the SVN status: execute the svn statuscommand, display the file name and its status, the status is M, indicating that the file is modified.

  • ② Revise the modification of the file: executesvn revert filename

  • ③ Check the SVN status again: execute the svn statuscommand, there is no display, indicating that the revocation is successful.

(3) Undo directory modification operation is the same as undo file modification, except that -R option is needed to restore directory svn revert -R dirname.

(4) Restore an already submitted version

  • ① To eliminate the old version, you must undo all changes in the old version and submit a new version. This operation is called reverse merge.

  • ② Command:, svn merge -r 22:21 filenamecurrent version 22, previous version 21.

5. SVN view historical information

The svn command can be used to remove past versions or specific modifications made by a version based on time or revision number.

(1) svn log: used to display the svn version author, date, path, etc.

  • ① Only view information between specific two versions:svn log -r 6:8
  • ② Only view the revision information of a certain file:svn log file_path/filename
  • ③ Only view the version modification information of the directory:svn log -v file_path

④ Display directory information with limited N records:svn log -l N -v

(2) svn diff: used to display detailed row-level detailed information.

  • ① Compare the working copy with the modification of the local repository:svn diff
  • ② Compare the modification of the working copy with the version library:svn diff -r 3 filename
  • ③ Compare the revision of the version library with the version library:, svn diff -r 2:3 filenameSeparate the version numbers with a colon.

(3) svn cat: View the content of a file in a specific version and execute it svn cat -r 版本号 filename.

(4) svn list: display a directory or a version of existing files, execute svn list -r 版本号 dir_path.

6. SVN branch

Branch is a copy of the trunk version (main trunk), which also has version control functions, and is independent of the main trunk. Finally, through the merge function, the branch can be merged into trunk and merged into a project.

(1) Create a branch in the local working copy:svn copy trunk/ branch/mybranch

(2) Check the SVN status:svn status

(3) Submit the newly added branch to the repository:svn commit -m "add my_branch"

(4) Merge my_branch branch into trunk:svn merge . ./branches/my_branch/

7. SVN tag

SVN supports the tag option, which can give a specific version of the code a tag, mainly used for milestones in project development, often representing a complete version that can be fixed.

(1) Create a tag branch in the local working copy:svn copy trunk/ tags/v1.0

(2) Check the SVN status:svn status

(3) Submit the tag content: svn commit -m "tags v1.0"

Six, TortoiseSVN tutorial

1. Introduction to TortoiseSVN

TortoiseSVN is a free open source GUI client for Subversion version control system

2. Install TortoiseSVN

(1) Download address: https://tortoisesvn.net/downloads.html , there is a download link for the language pack patch on the page.

(2) Run the downloaded TortoiseSVN installer

(3) Run the downloaded TortoiseSVN Chinese language pack

(4) Restart the computer and confirm that TortoiseSVN installation is complete.

(5) Modify the default language of TortoiseSVN

  • ① TortoiseSVN's default language is English, which can be modified to the installed language through settings.
  • ② Right-click on the blank space of the desktop—> TortoiseSVN—> Settings.
3. TortoiseSVN creates a server version repository

(1) Create a new directory locally and enter the newly created directory.

(2) Create a repository: right-click on the blank—> TortoiseSVN—> create a repository here

(3) After the version library is created, the server-side file will appear in the directory, which is the same as that created by the svnserve command.

4. TortoiseSVN creates a working copy

(1) Create a working directory locally and enter the created directory.

(2) SVN checkout: right-click on the blank, select SVN checkout (checkout), and a checkout dialog box will pop up.

  • ① Repository URL: the location URL of the repository (repository), ie svn: //192.168.0.1/svntest
  • ② Check out to directory: the working directory path created locally.
  • ③ Just check the depth and version default (the latest version), click OK.
  • ④ After checking out, you can see an .svnadditional hidden directory in the working directory.
5. TortoiseSVN client operation

(1) svn update operation: right-click on the blank of the working copy—> SVN update (U)

(2) svn add operation: right-click on the blank of the working copy—> TortoiseSVN—> increase (A)

(3) svn commit operation: right-click on the blank of the working copy—> SVN commit (C)

(4) svn copy operation: right-click on the blank of the working copy—> TortoiseSVN—> branch / tag (T)

(5) svn merge operation: right-click on the blank of the working copy—> TortoiseSVN—> merge (M)

(6) svn import operation: right-click on the blank of the working copy—> TortoiseSVN—> import (I)

(7) svn export operation: right-click on the blank of the working copy—> TortoiseSVN—> export (X)

(8) svn lock operation: right-click on the blank of the working copy—> TortoiseSVN—> acquire lock (K)

(9) svn unlock operation: right-click on the blank of the working copy—> TortoiseSVN—> unlock (K)

(10) svn cleanup operation: right-click on the blank of the working copy—> TortoiseSVN—> cleanup (C)

Disclaimer: This article is compiled from "SVN Chinese Manual", "TortoiseSVN Chinese Manual", "Rookie Tutorial-SVN Tutorial" and personal learning summary. It is a personal study note and is only used for learning and sharing. The download resources involved in this article are all from the Internet, and the copyright belongs to the original author. Please delete it consciously within 24 hours after downloading. If it is used for commercial purposes, please purchase the original copy. The infringement occurred due to the failure to purchase and pay in time. . If the content published in this article violates the related rights and interests, please contact me in time to delete it!

Guess you like

Origin www.cnblogs.com/davidesun/p/12758718.html