没有不值得去解决的问题,也没有不值得去学习的技术!

Best Practices for Branching and Merging in TortoiseSVN 1.8.8

The resolve conflicts window pops up

1. Creating a repository, based on VisualSVN Server 3.5.0

(1) Right-click Repositories and select: Create new Repository…, then select: Regular FSFS repository, as shown in Figure 1

Right-click Repositories and select: Create new Repository..., then select: Regular FSFS repository
Figure 1

(2) Set Repository Name to: branch, as shown in Figure 2

Set Repository Name: branch
Figure 2

(3) Select: Single-project repository(with the top-level ‘trunk’,’branches’ and ‘tags’ folders), as shown in Figure 3

Select: Single-project repository(with the top-level 'trunk','branches' and 'tags' folders)
Figure 3

(4) Select: Nobody has access, as shown in Figure 4

Select: Nobody has access
Figure 4

(5) Finish, as shown in Figure 5

Finish
Figure 5

(6) Right-click branch and select: Properties, as shown in Figure 6

Right-click branch and select: Properties
Figure 6

(7) Select the user groups that need authorization: Develpoer and front_end_developer, as shown in Figure 7

Select the user groups that need authorization: Develpoer and front_end_developer
Figure 7

(8) Set Permissions to: Read/Write, and click OK, as shown in Figure 8

Set Permissions to: Read/Write, and click OK
Figure 8

2. Checking out the trunk

(1) Create a new directory named branch, as shown in Figure 9

Create a new directory named branch, as shown in Figure 9
Figure 9

(2) Navigate to the branch directory, right-click in the blank space, and select: SVN Checkout, as shown in Figure 10

Navigate to the branch directory, right-click in the blank space, and select: SVN Checkout
Figure 10

(3) In the pop-up window, enter “https://192.168.2.63/svn/branch/trunk” in the repository URL field, leave the rest as default, and finally click OK, as shown in Figure 11

In the pop-up window, enter "https://192.168.2.63/svn/branch/trunk" in the repository URL field, leave the rest as default, and finally click OK
Figure 11

(4) Checkout complete, click OK, as shown in Figure 12

Checkout complete, click OK
Figure 12

3. Committing to the trunk

(1) Navigate to the branch directory and create a new file named 1.txt, as shown in Figure 13

Navigate to the branch directory and create a new file named 1.txt
Figure 13

(2) Navigate to the branch directory, right-click in the blank space, and select: SVN Commit, as shown in Figure 14

Navigate to the branch directory, right-click in the blank space, and select: SVN Commit
Figure 14

(3) In the pop-up window, select all, add a log message, and click OK, as shown in Figure 15

In the pop-up window, select all, add a log message, and click OK
Figure 15

(4) Commit complete, click OK

4. Creating branch v1

(1) Navigate to the branch directory, right-click in the blank space, and select “TortoiseSVN” -> “Branch/Tag” in sequence, as shown in Figure 16

Navigate to the branch directory, right-click in the blank space, and select "TortoiseSVN" -> "Branch/Tag" in sequence
Figure 16

(2) In the pop-up window, enter the branch address in the “To path” field. You can enter it manually or click the browse button on the right, as shown in Figure 17

In the pop-up window, enter the branch address in the "To path" field. You can enter it manually or click the browse button on the right
Figure 17

(3) Click the browse button to open the pop-up window, as shown in Figure 18

Click the browse button to open the pop-up window, as shown in Figure 18
Figure 18

(4) Select: branches, and click OK, as shown in Figure 19

Select: branches, and click OK
Figure 19

(5) In the pop-up window, the branch address “/branches” has been automatically filled in the “To path” field, as shown in Figure 20

In the pop-up window, the branch address "/branches" has been automatically filled in the "To path" field
Figure 20

(6) Edit the branch address in the “To path” field to “/branches/v1”. Under “Copy from”, select “Repository” and choose “HEAD revision in the repository”. Add a log message and click OK, as shown in Figure 21

Edit the branch address in the "To path" field to "/branches/v1". Under "Copy from", select "Repository" and choose "HEAD revision in the repository". Add a log message and click OK
Figure 21

(7) Branch creation complete, as shown in Figure 22

Branch creation complete
Figure 22

5. Switching to branch v1

(1) Navigate to the branch directory, right-click in the blank space, and select “TortoiseSVN” -> “Switch” in sequence, as shown in Figure 23

Navigate to the branch directory, right-click in the blank space, and select "TortoiseSVN" -> "Switch" in sequence
Figure 23

(2) In the pop-up window, enter the branch address in the “To path” field. You can enter it manually, select it from the drop-down list, or click the browse button on the right. Click OK, as shown in Figure 24

In the pop-up window, enter the branch address in the "To path" field. You can enter it manually, select it from the drop-down list, or click the browse button on the right. Click OK
Figure 24

(3) Switch complete, as shown in Figure 25

Switch complete
Figure 25

6. Committing a new file on branch v1

(1) Navigate to the branch directory (working copy) and create a new file named v1.txt, as shown in Figure 26

Navigate to the branch directory (working copy) and create a new file named v1.txt
Figure 26

(2) Right-click in the blank space, select: SVN Commit, select all, and add a log message, as shown in Figure 27

Right-click in the blank space, select: SVN Commit, select all, and add a log message
Figure 27

7. Switching to the trunk

(1) Navigate to the branch directory, right-click in the blank space, and select “TortoiseSVN” -> “Switch” in sequence, as shown in Figure 28

Navigate to the branch directory, right-click in the blank space, and select "TortoiseSVN" -> "Switch" in sequence
Figure 28

(2) In the pop-up window, enter the branch address in the “To path” field. You can enter it manually, select it from the drop-down list, or click the browse button on the right. Click OK, as shown in Figure 29

In the pop-up window, enter the branch address in the "To path" field. You can enter it manually, select it from the drop-down list, or click the browse button on the right. Click OK
Figure 29

(3) Switch complete, as shown in Figure 30

Switch complete
Figure 30

8. Committing a modification to the trunk (Note: The trunk is used for fixing bugs, not for adding new features. It is recommended to use it only for merging branches)

(1) Navigate to the branch directory and edit the file 1.txt, as shown in Figure 31

Navigate to the branch directory and edit the file 1.txt
Figure 31

(2) Right-click in the blank space, select: SVN Commit, select all, and add a log message, as shown in Figure 32

Right-click in the blank space, select: SVN Commit, select all, and add a log message
Figure 32

(3) Commit complete, as shown in Figure 33

Commit complete
Figure 33

9. Switching back to branch v1

(1) Navigate to the branch directory, right-click in the blank space, and select “TortoiseSVN” -> “Switch” in sequence, as shown in Figure 34

Navigate to the branch directory, right-click in the blank space, and select "TortoiseSVN" -> "Switch" in sequence
Figure 34

(2) In the pop-up window, enter the branch address in the “To path” field. You can enter it manually, select it from the drop-down list, or click the browse button on the right. Click OK, as shown in Figure 35

In the pop-up window, enter the branch address in the "To path" field. You can enter it manually, select it from the drop-down list, or click the browse button on the right. Click OK
Figure 35

(3) Switch complete, as shown in Figure 36

Switch complete
Figure 36

(4) At this point, opening 1.txt reveals that the operations performed in step 8 have been reverted, because they were committed to the trunk, not to branch v1, as shown in Figure 37

At this point, opening 1.txt reveals that the operations performed in step 8 have been reverted, because they were committed to the trunk, not to branch v1
Figure 37

10. Committing a modification on branch v1

(1) Navigate to the branch directory and edit the file 1.txt, as shown in Figure 38

Navigate to the branch directory and edit the file 1.txt
Figure 38

(2) Right-click in the blank space, select: SVN Commit, select all, and add a log message, as shown in Figure 39

Right-click in the blank space, select: SVN Commit, select all, and add a log message
Figure 39

(3) Commit complete, as shown in Figure 40

Commit complete
Figure 40

11. Merging the trunk into branch v1

(1) Navigate to the branch directory, right-click in the blank space, and select “TortoiseSVN” -> “Merge” in sequence, as shown in Figure 41

Navigate to the branch directory, right-click in the blank space, and select "TortoiseSVN" -> "Merge" in sequence
Figure 41

(2) In the pop-up window, under Merge type, select: Merge a range of revisions, and click Next, as shown in Figure 42

In the pop-up window, under Merge type, select: Merge a range of revisions, and click Next
Figure 42

(3) In the merge window, for the URL to merge from, you can enter it manually, select it from the drop-down list, or click the browse button on the right. Click OK, as shown in Figure 43

In the merge window, for the URL to merge from, you can enter it manually, select it from the drop-down list, or click the browse button on the right. Click OK
Figure 43

(4) Click the browse button to open the pop-up window, select: trunk, and click OK, as shown in Figure 44

Click the browse button to open the pop-up window, select: trunk, and click OK
Figure 44

(5) At this point, the merge source has automatically changed to “https://192.168.2.63/svn/branch/trunk”, as shown in Figure 45

At this point, the merge source has automatically changed to "https://192.168.2.63/svn/branch/trunk"
Figure 45

(6) For the revision range to merge, select: specific range (if you do not specify a revision range, all unmerged revisions will be selected), as shown in Figure 46

For the revision range to merge, select: specific range (if you do not specify a revision range, all unmerged revisions will be selected)
Figure 46

(7) For merge options, just keep the default settings here, as shown in Figure 47

For merge options, just keep the default settings here
Figure 47

(8) Before clicking the Merge button, you can test the merge first to check whether it succeeds and view the merge details, as shown in Figure 48

Before clicking the Merge button, you can test the merge first to check whether it succeeds and view the merge details
Figure 48

(9) The resolve conflicts window pops up, as shown in Figure 49

The resolve conflicts window pops up
Figure 49

(10) Remaining conflicts: Resolve all later, as shown in Figure 50

Remaining conflicts: Resolve all later
Figure 50

(11) The modifications made to the trunk will be synchronized into branch v1, and the automatic merge is complete, as shown in Figure 51

The modifications made to the trunk will be synchronized into branch v1, and the automatic merge is complete
Figure 51

(12) Open 1.txt, as shown in Figure 52

Open 1.txt
Figure 52

(13) Manually resolve the conflicts by editing 1.txt and deleting the 3 conflict files starting with 1.txt., as shown in Figure 53

Manually resolve the conflicts by editing 1.txt and deleting the 3 conflict files starting with 1.txt.
Figure 53

12. Committing the merged branch v1

(1) Commit, as shown in Figure 54

Commit
Figure 54

(2) Commit complete. At this point, branch v1 is fully synchronized with the trunk. If development on branch v1 is finished, you can merge branch v1 back into the trunk. Of course, if development on branch v1 needs to continue, you will repeatedly perform steps 10-11, as shown in Figure 55

Commit complete. At this point, branch v1 is fully synchronized with the trunk. If development on branch v1 is finished, you can merge branch v1 back into the trunk. Of course, if development on branch v1 needs to continue, you will repeatedly perform steps 10-11
Figure 55

13. Merging branch v1 into the trunk (Prerequisite: Development on branch v1 is finished)

(1) First, switch to the trunk; you can refer to step 7, as shown in Figure 56

First, switch to the trunk; you can refer to step 7
Figure 56

(2) Navigate to the branch directory, right-click in the blank space, and select “TortoiseSVN” -> “Merge” in sequence, as shown in Figure 57

Navigate to the branch directory, right-click in the blank space, and select "TortoiseSVN" -> "Merge" in sequence
Figure 57

(2) In the pop-up window, under Merge type, select: Merge a range of revisions, and click Next, as shown in Figure 58

In the pop-up window, under Merge type, select: Merge a range of revisions, and click Next
Figure 58

(3) In the merge window, for the URL to merge from, you can enter it manually, select it from the drop-down list, or click the browse button on the right. Click OK, as shown in Figure 59

In the merge window, for the URL to merge from, you can enter it manually, select it from the drop-down list, or click the browse button on the right. Click OK
Figure 59

(4) Click the browse button to open the pop-up window, select: branches/v1, and click OK, as shown in Figure 60

Click the browse button to open the pop-up window, select: branches/v1, and click OK
Figure 60

(5) At this point, the merge source has automatically changed to “https://192.168.2.63/svn/branch/branches/v1”, as shown in Figure 61

At this point, the merge source has automatically changed to "https://192.168.2.63/svn/branch/branches/v1"
Figure 61

(6) For the revision range to merge, select: specific range (if you do not specify a revision range, all unmerged revisions will be selected), as shown in Figure 62

For the revision range to merge, select: specific range (if you do not specify a revision range, all unmerged revisions will be selected)
Figure 62

(7) For merge options, just keep the default settings here, as shown in Figure 63

For merge options, just keep the default settings here
Figure 63

(8) Before clicking the Merge button, you can test the merge first to check whether it succeeds and view the merge details, as shown in Figure 64

Before clicking the Merge button, you can test the merge first to check whether it succeeds and view the merge details
Figure 64

(9) Automatic merge complete, as shown in Figure 65

Automatic merge complete
Figure 65

(10) View the contents of 1.txt; the modifications made in branch v1 will be synchronized into the trunk, as shown in Figure 66

View the contents of 1.txt; the modifications made in branch v1 will be synchronized into the trunk
Figure 66

14. Committing the merged trunk

(1) Right-click in the blank space, select: SVN Commit, select all, and add a log message, as shown in Figure 67

Right-click in the blank space, select: SVN Commit, select all, and add a log message
Figure 67

15. Showing the log

(1) Display the log messages. If you check “Include merged revisions”, you can view merge-related information, as shown in Figure 68

Display the log messages. If you check "Include merged revisions", you can view merge-related information
Figure 68

16. It is recommended to adjust steps 13-15 to 16-18 to merge branch v5 into the trunk (Prerequisite: Development on branch v5 is finished)

(1) First, switch to the trunk; you can refer to step 7

(2) Navigate to the branch directory, right-click in the blank space, and select “TortoiseSVN” -> “Merge” in sequence, as shown in Figure 70

Navigate to the branch directory, right-click in the blank space, and select "TortoiseSVN" -> "Merge" in sequence
Figure 70

(3) In the pop-up window, under Merge type, select: Merge two different trees, and click Next, as shown in Figure 71

In the pop-up window, under Merge type, select: Merge two different trees, and click Next
Figure 71

(4) In the merge window, enter the full folder address of the trunk in the From: field, as shown in Figure 72

In the merge window, enter the full folder address of the trunk in the From: field
Figure 72

(5) In the To: field, enter the path of branch v4. You can click the browse button on the right to select it. Click OK, as shown in Figure 73

In the To: field, enter the path of branch v4. You can click the browse button on the right to select it. Click OK
Figure 73

(6) At this point, the To: field has automatically changed to “https://192.168.2.63/svn/branch/branches/v5”, as shown in Figure 74

At this point, the To: field has automatically changed to "https://192.168.2.63/svn/branch/branches/v5"
Figure 74

(7) At the “Revision to” field, click the “Show Log” button next to the revision to view the starting revision of branch v5, which is: 26, as shown in Figure 75

At the "Revision to" field, click the "Show Log" button next to the revision to view the starting revision of branch v5, which is: 26
Figure 75

(8) At the “Revision from” field, select the revision, click the “Show Log” button next to the revision, and select revision: 25, which is the revision immediately preceding the starting revision 26 of branch v5 to be added, as shown in Figure 76

At the "Revision from" field, select the revision, click the "Show Log" button next to the revision, and select revision: 25, which is the revision immediately preceding the starting revision 26 of branch v5 to be added
Figure 76

(9) In the merge window, the final options are as shown in Figure 77. Click Next

In the merge window, the final options are as shown in Figure 77. Click Next
Figure 77

(10) Before clicking the Merge button, you can test the merge first to check whether it succeeds and view the merge details, as shown in Figure 78

Before clicking the Merge button, you can test the merge first to check whether it succeeds and view the merge details
Figure 78

(11) Automatic merge complete, as shown in Figure 79

Automatic merge complete
Figure 79

17. Committing the merged trunk

(1) Right-click in the blank space, select: SVN Commit, select all, and add a log message, as shown in Figure 80

Right-click in the blank space, select: SVN Commit, select all, and add a log message
Figure 80

18. Showing the log

(1) Display the log messages. If you check “Include merged revisions”, you can view merge-related information, as shown in Figure 81

Display the log messages. If you check "Include merged revisions", you can view merge-related information
Figure 81

19. Summary:

(1) Branches are primarily used for developing new features
(2) Merging occurs in the local working copy; as long as you do not commit, it will not affect the repository
(3) Before merging, you must perform an update and commit first to save your local modifications to the repository
(4) During parallel development between the branch and the trunk (merging other branches into the trunk), you should synchronize frequently by merging the trunk’s modifications into the branch, selecting “specific range” when merging
(5) Only after development on the branch is finished can you merge the branch into the trunk

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系