SVN usage tutorial Summary

Source: Internet
Author: User
Tags svn update version control system tortoisesvn

SVN introduction:

 Why SVN?

Each programmer generates many different versions during programming. This requires the programmer to effectively manage the code and quickly and accurately obtain the corresponding version as needed.

What is subversion?

It is a free/open-source version control system. A group of files are stored in the central version library, and each file and directory change is recorded. Subversion allows data recovery to earlier versions, or check the data modification history. subversion can access its version library through the network, so that users can operate on different computers.

I. Build and use SVN servers.

1. First, download and set up the svn server, as shown in the following figure: http://subversion.apache.org/packages.html. After you enter the network, scroll to the bottom of the page view:

I personally think it is best to use the visualsvn server and tortoisesvn client together. Click to open the visual SVN connection above, download the visual SVN server, and double-click the installation after the download is complete, such:

 

Click Next, as shown below:

Then click Next, and next, as shown below:

 

Click Next as follows:

 

Location refers to the installation directory of the visualsvn server. repositorys is to specify your version library directory. server port to specify a port. Use secure connection to check the mount to use a secure connection,

Click Next to go to the next step, such:

Click Install To Go To The following installation diagram:

After the installation is complete, click Next to go to the next step, as shown in figure

Click Finish to complete the installation. After the installation is complete, start the visualsvn Server Manager ,:

On the Right of the window, you can see information about the version library, such as status, log, user authentication, and version library.

To create a version library, right-click repositores in the left-side window, for example:

In the pop-up context menu, choose create new repository or create-> Repository:

Go to the next step, such:

Click Next, for example:

Click create, for example:

Click Finish to complete the basic creation.

2. users and groups need to be created and permissions need to be assigned..

1. Right-click the user group on the left side of the visualsvn Server Manager window, and choose create user or create-> User ,:

Click "user" to go to the following page:

Enter username and password, click OK, and enter the following information:

Click the Add button above, as shown in figure

Add longen0707 to the user (if there are multiple users, the operation is the same ).

2. Create a user group, right-click the user group on the left side of the visualsvn Server Manager window, and select create group or create-> group ,:

Click the group button to go to the page, for example:

In the pop-up window, set group name to developers, click Add, select developer in the pop-up window, add to this group, and click OK.

Next, we need to set permissions for the user group. Right-click myrepository and select Properties ,:

In the displayed dialog box, select the Security tab, click Add, select longen0707, and add the permission to read/write, for example:

Click OK.

Ii. Client SVN installation.

 1. First, we need to download "SVN turtle" and install it. For example, I downloaded the following:

 

After the installation is complete, for example, in my project in qiandaun1, right-click and you will see the following:

It indicates that SNV has been installed successfully!

2: checkout project file.

Create or go to the directory (for example, qianduan1), right click --> SVN checkout -->

The URL can be obtained from the svn server. I can right-click myrepositories to create a file.

 

The qianduan file is created, and then right-click it like this --> copy

You can.

Paste the copied version library URL, for example:

Click the OK button to search the file, as shown in the following figure:

For example:

 

Note:

. The SVN hidden directory records two key information items: the reference version of the working file and the timestamp of the last update of a local copy. Do not manually modify or delete this file. SVN hides directories and files in them !!, Otherwise, your local copy of work (static attempt) will be damaged and you will not be able to perform any further operations.

1) tortoisesvn icon Introduction

A new detected work copy uses a green check box to indicate that the Subversion status is normal.

After you start editing a file, the status changes to modified, and the icon reload changes to a red exclamation point. In this way, you can easily see that the files have been modified from your last update work copy and need to be submitted.

If a conflict occurs during the submission process, the icon becomes a yellow exclamation point.

The plus sign indicates that a file or directory has been planned to be added to version control.

2) Basic tortoisesvn client operations:

1.SVN check-out (SVN checkout)

Right-click a folder or directory and choose SVN check-out from the shortcut menu, as shown in

Click, enter the directory address of the version library in the URL box of the pop-up window, and then click OK, as shown in figure

 

Click OK, for example:

In the displayed dialog box, enter the user name and password. After the verification is successful, the project file is downloaded from the remote server to the local working directory.

Click OK, as shown in:

2.Add)

Under the testproject file, you can create a new B .txt file and submit it to the version library using the following two methods:

1. first, we will mention the change list, then commit it to the configuration library, select Add file, right-click the svn menu and execute "add" Operation submitted to "change list ", right-click the svn menu and execute "SVN commit" to submit it to the version library.

2. Do not submit the changes to the Change List. Instead, select the file in the commit configuration library and right-click the svn menu to execute the svn commit operation.

3.Delete)

If the deleted file is not in the version library, you can directly delete the file using the delete operation of the operating system.

If the file to be deleted is already in the version library, the method to delete it is as follows:

  1. Select the deleted file, right-click the svn menu to execute the delete operation, select the parent directory of the deleted file, and right-click the svn menu to execute SVN commit ".

Use the delete operation of the operating system to delete the file, select the parent directory of the deleted file, right-click the svn menu and execute "SVN commit", and select the deleted file from the change list. For example:

4.Rename)

Modify the file name, select the file or folder to be renamed, right-click "tortoisesvn à rename", enter a new name in the displayed dialog box, and click "OK, submit the file or folder after the file name is modified to the svn server through "SVN commit.

5.SVNSVN revert)

Right-click the file or folder to be rolled back, and select "Update to reversion…" in the tortoisesvn pop-up menu ..." A window will pop up, as shown below:

For example, to roll back to version 10th, you only need to enter the corresponding version number in revision, and then click OK.

 6.Check for updates)

This function shows which modifications you have made have not been submitted. This function does not only show changes to files, but all changes can be seen, including adding files or directories, delete files or directories, move files or directories, etc. If you click to check the version library, you can also see the changes in the version library, which files have been submitted by others, you have not updated it to the local machine, as shown below:

 7.SVNSVN update)

The updated local code is consistent with the latest version on the svn server. You only need to right-click the folder to be updated or right-click the blank area under the file, select "SVN Update" (get the content in the specified version, right-click to execute "Update to reversion" in the svn menu), and you will be able.

 7.1 how to resolve conflicting files

For each conflicting file subversion, three files are placed in your directory:

Why does it produce conflicting code? The reason is very simple because different people modify the same place of the same file at the same time. At this time, he submitted the file. If I didn't submit it, I couldn't submit it, at this time, we need to update the file first and then submit it. If a conflict occurs, the above three files will be generated.

The solution is as follows::

First, we can look at the 1.txt Code as follows:

<. Mine

Aaaasdf11222333 dderderder

========

B >>>>>>>. R5

After all, I will drop more code, and 1.txt will become like this.

Aaaasdf11222333 dderderder

Submit, or not, as shown below:

Why? The conflict will generate the above three files, and the above three files cannot be submitted. The code and explanations of these three files are as follows:

  1. 1.txt. Mine is your own file before the conflict. You can see the following content:

Aaaasdf11222333 dderderder

2. 1.txt. R4 is a local version file before the conflict

Content: aaaasdf11222333

3. 1.txt. R5 is a version submitted by someone else before you

The content is as follows: B

Where, <. mine ..... the codes between ======== are yours, and ======== ...... >>>>>>>>>>. r5 is part of the code that someone else conflicts with you.

In this way, it is not difficult to understand why there is such a strange conflict, because the same piece of code you modified will of course lead to a conflict.

The solution is as follows:

  1. For example, the conflict content in 1.txt is as follows:

<. Mine

6666666666666600000

========

66666666666aaaaaaaaaa666

>>>>>>>. R16
As mentioned earlier, <. Mine ...... ========

...... The code between them is the code modified before I generate a conflict,

========…… >>>>>>> . R16In the middle ...... The Code of conflicted with me is the part of the Code. From the code above, we can see that aaaaaaaaa was added by my colleagues, and 00000 was added by me.

    1. Use the revert (rollback) operation. This operation means that the user abandons his/her update code and directly submits it. At this time, your code will make the latest code on the server, that is, the new Code submitted by user a will not be submitted, as shown below:

      After clicking the OK button, you can see that all the other three files are automatically deleted, and the 1.txt code is changed to the following code:

      66666666666aaaaaaaaaa666

      That is, the Code submitted by user a. I need to copy the updated code myself to submit the commit.

    2. For example, the conflicting code 3.txt is as follows:

      <. Mine

      333333338888888888888 ========

      3333cccccccc3333 >>>>>>>. R16

      Through the first point, we know that the content 333333338888888888888 is the content that has not been generated before the conflict since I modified it. The Code 3333cccccccccc3333 is the code submitted by user, I learned from the above that the newly added content of user a is ccccccc, and the newly added content of user a is 8888888.

      The second solution is as follows:

Select File-> right-click editconficts: This method requires the conflicting parties to unify the code and then submit it. This not only resolves conflicts, but also ensures that the code is correct, because only one side of the Code is submitted.

As shown in, the red part is the conflicting code: theirs indicates the latest code on the current server, mine indicates the code modified by myself, and merged indicates the Merged Code. Right-click the red icon and choose "use this text block" to use this part of the Code as the Merged Code.

Next, let's talk about how important code is overwritten due to conflicts. If the measures taken are incorrect when a conflict occurs, some code may be lost. It is also easy to restore the previous code.

Select File-> right-click show log. You can view all the versions submitted earlier, right-click the version you want to restore, and select revert to this version.

SVNSubmit (SVN commit)

SVN submission submits modifications made in the workspace, including modifications to the file content, addition, deletion, naming, and moving of files or directories. As shown in:

8. Show log)

You can use this function to find out who and when to perform the operations on those files in that directory, such:

 9.Version library browsing (repo-browser)

This function is used to browse the database to be viewed. Right-click the local folder, select tortoisesvn à repo-browser, enter the database address in the pop-up dialog box, and then enter the user name and password, you can view the content of the version library. Here, you can see who has locked the files, for example:

3. Create branch merge operations

Why create and merge branches in the project?

For example, if all the files of my current project are placed on the trunk (trunk), new requirements need to be added due to changes in requirements, but we need to continue development on the trunk, here we can create a new branch to add new requirements, continue development on the trunk, and merge it into the trunk when there is no problem with the code on the branch.

The biggest purpose of creating a branch is to perform parallel development with the main line without affecting the development of the main line.

What should I do?

 Suppose I create a local folder named "test" with two folders, trunk (the code on the trunk) and branch (the code on the Branch), as shown below:

1. Extract the code on the trunk first.

Right click trunk --> right click --> click SVN checkout --> A dialog box is displayed, as shown in:

The above URL is obtained from the visual SVN server, as shown below:

 

Right-click qianduan3 --> copy URL to clipboard.

The qianduan3 project has the following files, as shown in:

Finally, click the checkout button above to obtain the code from the remote server on the trunk, as shown below:

 

2. Create a branch

To create a branch from a trunk (trunk), follow these steps:

1. Right-click trunk --> branch/Tag, for example:

The pop-up dialog box is as follows:

Click OK to add newbranch ON THE visualsvn serval server, which is copied from the files on qianduan3, as shown below:

Now let's take a look at the local branch folder. Now I can directly go to the Branch file and right-click --> chenckout to extract all the files under newbranch, as shown below:

 

Click OK to extract the file, as shown in:

The Branch is currently created on the svn server and is not updated locally. You can right-click the local branch folder --> Update to update the branch code, as shown below:

4. merge branches to the trunk

For example, I will add a new 3.txt file to branch's branch and submit it as follows:

I want to merge the code 3.txt on the branch to the trunk on the trunk. How can I merge it now? The procedure is as follows:

1. Go back to the trunk folder and right-click the folder --> tortoisesvn --> merge, as shown in:

In the displayed window, as shown in:

 

Click Next, as shown in:

Next, click [next] Next, as shown in:

 

It can be seen that an additional 3.txt is added to the trunk trunk, which is merged from the branch.

5. Merge the trunk to the branch.

If there are some updates on the trunk, such as jar package updates, and so on, how should we update these updates to the branch? For example, if I create a new 4.txt file on the backbone, for example:

 

My current branch directory is as follows:

Now I want to merge the 4.txt file on the trunk to the Branch. What should I do?

The procedure is as follows.

1. In the branch, right-click Branch --> tortoisesvn --> merge, as shown in:

 

After a new window is displayed, as shown in:

Click Next, as shown in:

 

Continue to the next step, for example:

You can see that the branch Branch also has the 4.txt file on the trunk, that is, merge the trunk to the branch, as shown in:

SVN usage tutorial Summary

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.