二、分支创建于合并
1、创建一个代码文件夹main
>[root@node2 svndata]# cd release/
[root@node2 release]# mkdir ./main
[root@node2 release]# svn add ./main/
A main
[root@node2 release]# svn commit ./main/ -m "zhugan"
Adding main
Committed revision 2.
2、创建分支
>[root@node2 release]# svn copy svn://10.0.0.6:/release/main svn://10.0.0.6:/release/beta -m "fenzhichuangjian"
Committed revision 3.
>[root@node2 release]# svn update
Updating '.':
A beta
Updated to revision 3.
[root@node2 release]# ll
total 0
drwxr-xr-x. 2 root root 6 Oct 22 17:19 beta
drwxr-xr-x. 2 root root 6 Oct 22 17:16 main
-rw-r--r--. 1 root root 0 Oct 22 17:10 test.php
3、查看分支状态
[root@node2 release]# svn log ./beta/
------------------------------------------------------------------------
r4 | admin | 2018-10-22 17:27:46 +0800 (Mon, 22 Oct 2018) | 1 line
node3 test files
------------------------------------------------------------------------
r3 | admin | 2018-10-22 17:18:34 +0800 (Mon, 22 Oct 2018) | 1 line
fenzhichuangjian
------------------------------------------------------------------------
r2 | admin | 2018-10-22 17:16:45 +0800 (Mon, 22 Oct 2018) | 1 line
zhugan
------------------------------------------------------------------------
注间事项:
a),创建分支,只能在同一个仓库内进行,跨仓库是不行的。会提示svn: No repository found in 'svn://10.0.0.6'
b),创建分支时,注意加上注释,不然会报错
4、分支合并
分别用node2 和node3在beta分支中创建文件或文件夹 并分别提交到svn代码仓库
>[root@node3 beta]# touch node3_test.log
[root@node3 beta]# mkdir node3_test
[root@node3 beta]# svn add node3_test.log node3_test
A node3_test.log
A node3_test
[root@node3 beta]# svn ci node3_test node3_test.log -m "node3 test files"
Adding node3_test
Adding node3_test.log
Transmitting file data .
Committed revision 4.
>[root@node2 beta]# svn update
Updating '.':
A node3_test
A node3_test.log
Updated to revision 4.
[root@node2 beta]# svn add test_node2.txt node2_test/
A test_node2.txt
A node2_test
[root@node2 beta]# svn ci test_node2.txt node2_test/ -m "node2 test files"
Adding node2_test
Adding test_node2.txt
Transmitting file data .
Committed revision 5.
>[root@node2 beta]# ll
total 0
drwxr-xr-x. 2 root root 6 Oct 22 17:26 node2_test
drwxr-xr-x. 2 root root 6 Oct 22 17:28 node3_test
-rw-r--r--. 1 root root 0 Oct 22 17:28 node3_test.log
-rw-r--r--. 1 root root 0 Oct 22 17:25 test_node2.txt
>[root@node3 beta]# ll
total 0
drwxr-xr-x. 2 root root 6 Oct 22 17:28 node2_test
drwxr-xr-x. 2 root root 6 Oct 22 17:26 node3_test
-rw-r--r--. 1 root root 0 Oct 22 17:26 node3_test.log
-rw-r--r--. 1 root root 0 Oct 22 17:28 test_node2.txt
记得update 此时发现 beta文件夹内已经存在生成的测试文件。
5、合并分支到主干:
1)查找分支版本
方法一
[root@node2 release]# cd beta/
[root@node2 beta]# svn log --stop-on-copy
------------------------------------------------------------------------
r4 | admin | 2018-10-22 17:27:46 +0800 (Mon, 22 Oct 2018) | 1 line
node3 test files
------------------------------------------------------------------------
r3 | admin | 2018-10-22 17:18:34 +0800 (Mon, 22 Oct 2018) | 1 line
fenzhichuangjian
------------------------------------------------------------------------
最后一个r3就是创建分支时候的reversion
方法二 cd main
命令:svn -q --stop-on-copy 分支URL,这条命令会查询出自创建分支以后分支上的所有修改,最下面的那个版本号就是我们要找的版本号.
示例:svn log -q --stop-on-copy svn://10.0.0.6/release/beta
[root@node2 beta]# svn log -q --stop-on-copy svn://10.0.0.6/release/beta
------------------------------------------------------------------------
r5 | admin | 2018-10-22 17:28:43 +0800 (Mon, 22 Oct 2018)
------------------------------------------------------------------------
r4 | admin | 2018-10-22 17:27:46 +0800 (Mon, 22 Oct 2018)
------------------------------------------------------------------------
r3 | admin | 2018-10-22 17:18:34 +0800 (Mon, 22 Oct 2018)
------------------------------------------------------------------------
2)合并到主干
命令:svn -r 分支版本号:HEAD 分支的URL
解释:HEAD为当前主干上的最新版本
示例:
cd main
svn merge -r 5:HEAD svn://192.168.1.177/tags/beta_2009_12_24
查看可知 主干最新版本为r2
执行
>[root@node2 main]# svn merge svn://10.0.0.6:/release/beta .
--- Merging r3 through r5 into '.':
A test_node2.txt
A node2_test
A node3_test
A node3_test.log
--- Recording mergeinfo for merge of r3 through r5 into '.':
U .
[root@node2 main]# ll
total 0
drwxr-xr-x. 2 root root 6 Oct 22 17:40 node2_test
drwxr-xr-x. 2 root root 6 Oct 22 17:40 node3_test
-rw-r--r--. 1 root root 0 Oct 22 17:40 node3_test.log
-rw-r--r--. 1 root root 0 Oct 22 17:40 test_node2.txt
分支合并完成 然后提交到代码库
>[root@node2 main]# svn ci -m "hebing"
Sending .
Adding node2_test
Adding node3_test
Adding node3_test.log
Adding test_node2.txt
Committed revision 6.
在node3上面执行update 同步
>[root@node3 beta]# cd ../main/
You have new mail in /var/spool/mail/root
[root@node3 main]# svn update
Updating '.':
A test_node2.txt
A node2_test
A node3_test
A node3_test.log
U .
Updated to revision 6.
[root@node3 main]# ll
total 0
drwxr-xr-x. 2 root root 6 Oct 22 17:42 node2_test
drwxr-xr-x. 2 root root 6 Oct 22 17:42 node3_test
-rw-r--r--. 1 root root 0 Oct 22 17:42 node3_test.log
-rw-r--r--. 1 root root 0 Oct 22 17:42 test_node2.txt
分支合并完成