The creation and merging of SVN branches

Source: Internet
Author: User
Tags create directory svn svn update

If the trunk is like this,

A---->b------>c----->d------------>e

A b c d e represents the version number, respectively.

Suddenly discovering that the project introduced a bug in version e, it may take a while to modify the bug, which means that if you modify the code directly at E, it may affect others to continue development, one way is to copy E's code to another place (create a branch), Fix bugs on this branch and fix bugs, merge them into the trunk, and continue with development.

A---->b------>c----->d------------>e-------->f the------------>g (trunk continues normal development)

|

| Create a Branch

V

E1-------->f1-------->G1

When a branch arrives at G1, the bug is fixed, and the branch needs to be merged into the trunk, and it becomes the following state

A---->b------>c----->d------------>e-------->f------------>g-------> H-------->

| ^

                                                    | Create a branch                                   |

V |

E1-------->f1--------->G1--------->

G and G1 two code merge (may need to resolve conflicts to merge) become H then continue development

The demo code is as follows

: If all the items are placed in the Svn://localhost/java

Create a new DRP project SVN://LOCALHOST/JAVA/DRP

1 Create the target locally

Jixiuf@jf/tmp/svntmp $ mkdir Drp/{trunk,branches,tag} Create directory

Jixiuf@jf/tmp/svntmp $touch Drp/trunk/{hello.java,hello2.java,hello3.java} create several files

Jixiuf@jf/tmp/svntmp $ tree directory structure as follows jixiuf@jf/tmp/svntmp $ trees
.
└──drp
├──branches
├──tag
└──trunk
├──hello2.java
├──hello3.java
└──hello.java
4 directories, 3 files

Trunk: The skeleton directory of the project, branches is the branch directory,

The project is then submitted to SVN://LOCALHOST/JAVA/DRP, which is the creation of the SVN://LOCALHOST/JAVA/DRP project

Jixiuf@jf/tmp/svntmp $ svn import-m "Create the project DRP" DRP/SVN://LOCALHOST/JAVA/DRP

Delete this DRP directory and download it from the remote

Jixiuf@jf/tmp/svntmp $ rm drp/-RF

Jixiuf@jf/tmp/svntmp $ svn Co SVN://LOCALHOST/JAVA/DRP

Jixiuf@jf/tmp/svntmp $ cd DRP

JIXIUF@JF/TMP/SVNTMP/DRP $ svn log look at the logs and create a project in version 84 o'clock DRP
------------------------------------------------------------------------
R84 | Jixiuf | 2010-05-13 14:44:21 +0800 (four, 2010-05-13) | 1 lines

Create the project DRP------------------------------This is running SVN import-m "Create the project DRP" drp/svn:// Log information added when LOCALHOST/JAVA/DRP
------------------------------------------------------------------------

The r84 at this point is the E state above (a bug was found and a decision was made to create a branch to resolve the bug).

JIXIUF@JF/TMP/SVNTMP/DRP $ svn cp-m "Create a branch" Svn://localhost/java/drp/trunk/svn://localhost/java/drp/branches/debu gDrp1.0

The submitted version is 85.

Create a branch and name it debugDrp1.0

Because the local DRP is R84 version, and the server side is R85 version, need to update

JIXIUF@JF/TMP/SVNTMP/DRP $ svn up is shorthand for update (same as SVN update command)

Jixiuf@jf/tmp/svntmp/drp $ tree Now look at the directory structure (you'll find a debugDrp1.0 directory under the branches directory, and the file under the directory is the file in the trunk directory, which is called creating the branch)
.
├──branches
│  └──debugdrp1.0
│      ├──hello2.java
│       ├──hello3.java
│      └──hello.java
├──tag
└──trunk
   ├──hello2.java
   ├──hello3.java
  & nbsp └──hello.java
4 directories, 6 files

JIXIUF@JF/TMP/SVNTMP/DRP $ svn log look at the logging
------------------------------------------------------------------------
R85 | Jixiuf | 2010-05-13 14:51:35 +0800 (four, 2010-05-13) | 2 lines

Create a branch

------------------------------------------------------------------------
R84 | Jixiuf | 2010-05-13 14:44:21 +0800 (four, 2010-05-13) | 1 lines

Create the Project DRP
------------------------------------------------------------------------

If the file with the bug is Hello.java

Modify the Hello.java in the branches/debugdrp1.0 directory

If so, modify the bug

JIXIUF@JF/TMP/SVNTMP/DRP $ echo "Bug corrected" >>branches/debugdrp1.0/hello.java

is to add a bug to the end of the file Hello.java corrected these words

To show that if a flush is resolved, some information is also added to the Hello.java in the trunk to create a conflict


JIXIUF@JF/TMP/SVNTMP/DRP $ echo "information added to Hello.java in the trunk to create a conflict" >> Trunk/hello.java

Now submit to Server

JIXIUF@JF/TMP/SVNTMP/DRP $ svn ci-m "Modify the Hello.java in branches/debugdrp1.0 and trunk"
Sending Branches/debugdrp1.0/hello.java
Sending Trunk/hello.java
Transfer file Data ...
The submitted version is 86.

JIXIUF@JF/TMP/SVNTMP/DRP $ svn up update to latest version 86

The bug has now been modified in branches/debugdrp1.0, and the file Hello.java has been modified in the trunk trunk in the process.

People who fix bugs find that there are some new changes in the trunk that need to be added to these new changes,

Which is to merge the things in the trunk into the branches,

=============================================================

JIXIUF@JF/TMP/SVNTMP/DRP $ cd branches/debugdrp1.0/to the root directory of the branch debugDrp1.0

Then take a look at the log

jixiuf@jf/tmp/svntmp/drp/branches/debugdrp1.0 $ svn Log View all logs, (note that the branch log includes the trunk log before the branch was created, and the independent log that was developed on the branch after the branch was created, now view all Directory
------------------------------------------------------------------------
r86 | Jixiuf | 2010-05-13 15:13:23 +0800 (four, 2010-05-13) | 1 lines
Modify the Hello.java in branches/debugdrp1.0 and trunk
------------------------------------------------------------------------
R85 | Jixiuf | 2010-05-13 14:51:35 +0800 (four, 2010-05-13) | 2 lines
Create a branch
------------------------------------------------------------------------
R84 | Jixiuf | 2010-05-13 14:44:21 +0800 (four, 2010-05-13) | 1 lines
Create the Project DRP
------------------------------------------------------------------------

jixiuf@jf/tmp/svntmp/drp/branches/debugdrp1.0 $ svn Log--stop-on-copy (here to view the log on the branch that was independently developed after he built the branch, excluding the log on the backbone)
------------------------------------------------------------------------
r86 | Jixiuf | 2010-05-13 15:13:23 +0800 (four, 2010-05-13) | 1 lines
Modify the Hello.java in branches/debugdrp1.0 and trunk
------------------------------------------------------------------------
R85 | Jixiuf | 2010-05-13 14:51:35 +0800 (four, 2010-05-13) | 2 lines
Create a branch
------------------------------------------------------------------------

jixiuf@jf/tmp/svntmp/drp/branches/debugdrp1.0 $ svn Merge Svn://localhost/java/drp/trunk merges the trunk directory into the current directory
A conflict was found in "Hello.java".
Select: (P) postpone, (DF) Show all differences, (e) Edit,
(MC) My version, (TC) The version of others,
(s) Show all options:
As a result, the following prompts say that there is a hello.java conflict, and then it provides several solutions,

P postponed, (will produce multiple Helllo.java versions of files in the same directory in Hello.java, there are r84 versions, this is the previous version of the conflict, and the version on the branch, the trunk version, and a diff comparison generated) Need to manually modify Hello.java and then delete several other versions, then svn CI resubmit

DF just shows differences in files, e edit files directly resolve conflicts

At this point I choose E

An editor appears with the following contents

    <<<<<<<. Working
  Bug Modified
   =======
    Information added to Hello.java in the backbone to create a conflict
   >>>>>>>. merge-right.r86
~                                                                                                                                  
~

It means that there is a "bug corrected" line in the directory of the current work (. Working) Hello.java

The. merge-right.r86 file (that is, this line in the Hello.java in the trunk) "adds information to Hello.java in the trunk to create a conflict."

Merge files as

Bug has been fixed
Information added to Hello.java in the trunk to create a conflict

After conflict resolution, select R

The trunk is then merged into the current branch to view a

jixiuf@jf/tmp/svntmp/drp/branches/debugdrp1.0 $ cat Hello.java
Bug has been fixed
Information added to Hello.java in the trunk to create a conflict

====================================================

In addition, although the code in the branch has fixed the bug and has the most recently added code in the trunk

and merge it into the trunk.

jixiuf@jf/tmp/svntmp/drp/branches/debugdrp1.0 $ cd/tmp/svntmp/drp/trunk/

Jixiuf@jf/tmp/svntmp/drp/trunk $ svn Merge svn://localhost/java/drp/branches/debugdrp1.0

Also, after resolving a conflict, you can continue to develop code in trunk

A---->b------>c----->d------------>e-------->f------------>g-------> H-------->

| ^

                                                    | Create a branch                                   |

V |

E1-------->f1--------->G1--------->


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.