SVN branch and merge (SVN switching branch and merge) detailed

Source: Internet
Author: User
Tags tortoisesvn

The following practice is primarily reference to TORTOISESVN's help documentation and subversion's online documentation, Subversion's online documentation:http://svnbook.red-bean.com/en/1.5/svn-book.html

First talk about what is branch. According to subversion, a branch is a copy of a development line (usually the trunk), see:

The significance of the existence of branch is that, without disturbing the trunk, and trunk parallel development, to be developed after the end of the merger back to the trunk, in the branch and trunk of their respective development process, they can continue to submit their own changes, This allows each modification to be recorded in the repository.

Imagine the scenario where your project needs to develop a new feature that might modify most of the files in your project, while another colleague of yours is working on the bug fix, if your new feature is not developed in branch and developed directly in the trunk, Then you are most likely to affect another colleague's bug fix, who may encounter a variety of problems in bug fixes, because your frequent commit code introduces too many destabilizing factors. You may say that I do not submit in the process of development, and until I complete the development of the end of the submission, yes, you can do so, and then version control what to do? Maybe wait until you finally commit the code (maybe a week, maybe two weeks?) ), you will find a lot of conflict waiting for you resolve ...

So what's the right thing to do? Using branch, create a branch from the trunk and then develop it on your branch, and then merge it into the trunk after the development is complete.

About Branch first here, here's what's called Merging. It's good to understand that when the branch development is complete (including the necessary tests), the changes in the branch are synchronized to the trunk, which may include modifying files, adding files, deleting files, and so on.

Speaking of which, it seems that this article is almost over, not just branching and merging? Simply talk about how to set up a branch and how to merge it, and it may take only two commands, or just a few clicks of the mouse and then the keyboard to knock twice. In fact, things are far from so simple, the students who love to use their brains may ask, will branch changes to the trunk, and the above said directly in the trunk of all development and then submit what is the difference? You're not finally dealing with a lot of conflict?

This question is very good, in fact this is the focus of this article: branch and trunk in the process of parallel development how to perceive each other, how can branch in the development process and trunk farther and farther, resulting in the final can not be merged? Imagine if, in the course of your development of the branch, a class file in the trunk has been deleted (this could be another guy who was developed on another branch for two weeks before merging into the trunk), and you have made a lot of changes to the class file, How do you feel the pain when you finally merge back to the trunk? The only way to solve this problem is to keep the branch in sync with the trunk, you need to know in time what the trunk has changed, whether these changes will affect the new features you are developing, and if necessary, you must adjust the branch code in time to make it "compatible" with the trunk.

So how do you keep branch and trunks in sync? Merge, merge from trunk to branch, you heard wrong, from trunk to branch. Regarding the merger of TORTOISESVN, there are several points to note:

    • TortoiseSVN merge occurs locally, also in your working copy, you don't have to worry too much about the code in repository.
    • Whether you merge from trunk to branch or eventually merge back to trunk from branch, it is best to update before each merge, then make the local modifications all commit first, protect the scene, if the merger is not ideal at any time can be revert
    • After the merge is complete, see if it compiles correctly, then test the validation, and finally commit the merged changes to the repository

Next I'll show you how to do a complete branching and merging at a time, including creating branches, branching, branching and mainline synchronization, branching into the mainline, and even how to create a test repository locally.

First need to install TortoiseSVN, I installed the version is: TortoiseSVN 1.6.15, Build 21041-32 Bit, 2011/03/23 18:00:27

1, the creation of local repository

The creation of repository is simple, assuming I want to create repository in the D:\TortoiseSVN\TestRepository directory, just right-testrepository the directory, select TortoiseSVN "Create repository Here" completes the creation of repository.

2. Check out

If you want to Check out to D:\TortoiseSVN\TestSVN, it is also very simple to create a testsvn directory under the D:\TortoiseSVN directory, then right-click on the directory and select "SVN Check out ..." in the pop-up window " URL of repository "fill in" File:///D:/TortoiseSVN/TestRepository ", other default can, finally click OK.

3. Trunk to create a new project MyProject

It is quite simple not to repeat, only to list the changes made by this operation:

4. Create Branch

Right-click on the/trunk/myproject directory, select "TortoiseSVN", then "Branch/tag ...", and in the "to URL" of the pop-up window, enter the address of the branch, where the target revision select Head revision , as shown, click OK to add log after the branch is established. This operation is very fast, the new branch in the repository is actually a revision to the trunk of a soft connection only, and did not really copy the file.

5. Check out Branch

Right-click the TESTSVN directory and select "TortoiseSVN Update" to download the branch you just established back to local. Enter the/branches/myproject directory and you will find that its file structure is identical to the/trunk/myproject.

6, Branch submit a new file

7. The trunk is immediately followed by a modification

8, Branch again to submit a change

9. Synchronize the changes in the trunk to the branch

6-8 demonstrates that branch and trunks are developed independently and in parallel. In order to prevent the "wrong" on the road farther, now branch realize that it is time to synchronize with the trunk (merge trunk to branch).

First, in the local trunk of the first update, there is conflict resolution conflict, ensure that the trunk and repository are fully synchronized, and then right-click on the/branches/myproject, select "TortoiseSVN", then "Merge ", in the popup window, select the first item" merge a range of revision ", this type of merge has been introduced very clearly, applicable to a branch or the main line to submit the changes between the multiple revision to merge on another branch.

After clicking Next, the following window appears:

Because it is to be merged from the trunk to branch, it is natural that the "URL to merge from" should be the path of the trunk, "Revision range to merge" very well understood, Is that you want to merge which revision of the trunk into the branch, which can be a series of revision, such as 4-7,15-head, or a separate revision number. Because the trunk modifies the talk () method in the R4, the revision in the Person.java can only be filled in 4. Click Next to appear:

Just leave the default settings here. Before you click the merge button, you can test the merge to see if it's successful or not, and the details of the merge. When you click the Merge button, the trunk changes are synced to branch.

10, after the submission of the combined branch

At this point, Branch has been fully synchronized with the trunk, branch and trunk code get along very well, there is no conflict, if the branch has been developed, it is time to merge branch back to the trunk, of course, if the branch to continue to develop, Then you will continue to repeat the 6-10 steps.

11. Merge branch back to Trunk

Right-click on the/trunk/myproject (note Right-click on the main Line's directory), select "TortoiseSVN", then "Merge ...", and in the popup window, merge type Select the second item "reintegrate a branch" , this type of merge is suitable for merging all changes back to the mainline after the branch development is complete.

After clicking Next, the following window appears:

Here, the from URL selects/branches/myproject without selecting the revision number, and reintegrate merges all the modifications on branch into the trunk. The next steps, as in the 9th step above, are no longer verbose. If no accident, branch will successfully merge into trunk, all you need to do is to get the merged trunk hurriedly commit!

12. Submit the merged trunk

So easy ...

13. Delete Branch

If you think your new add-on feature has been developed, you can delete your branch

Here I have shown you the whole process, my sweat is down, I want to strike, but in the end we still look at all the log information, through log can find all the things we do:

R1-R7 is exactly what I was doing, from the message you can find out what I've done with trunks and branch, and in the lower left corner of the Log Messages window, you can see the additional merge by checking "Include merged revisions". Information:

The gray is the log associated with the merge, a total of two times the merge, the first time in R6, in R6, branch merge the trunk in the R4 when the changes submitted; the second is in R7, where the trunk incorporates all the changes R7 from branch to R2.

Original: http://www.cnblogs.com/cxd4321/archive/2012/07/12/2588110.html

SVN branch and merge (SVN switching branch and merge) detailed

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.