在git flow的分支模型出现之前,svn在项目中的应用广泛地使用trunk/branches/tags作为约定俗成的使用方式。这篇文章简单介绍一下trunk/branches/tags的使用方式。
注意事项:首先需要说明的是虽然在很多项目中都有trunk/branches/tags,但这并不意味着这是必须的,这些的名称和布局方式也不是固定的,在svn中其本质也只是被管理的目录和链接而已。
trunk/branches/tags的使用方式之所以一度非常流行,因为这种方式整理除了分支模型的最重要的几个重点,可以用与辅助进行如下常见场景的团队的软件开发:
而trunk/branches/tags也分别代表着不同的意义:
类别 | 说明 |
---|---|
trunk | 主线分支,一般进行日常维护的分支,在git的模型中与master分支类似 |
branches | 特性分支/bug对应分支,git中普通的分支概念,用于特性开发/bug对应等常见的场景 |
tags | 发布版本的基线管理,一般tag都是只读,不能进行修改。 |
项目开发根据具体情况,结合功能模块,trunk/branches/tags的构成方式并非千篇一面,常见构成有如下方式
目录1 | 目录2 |
---|---|
trunk | 模块1 |
模块2 | |
branches | 模块1 |
模块2 | |
tags | 模块1 |
模块2 |
或者
目录1 | 目录2 |
---|---|
模块1 | trunk |
branches | |
tags | |
模块2 | trunk |
branches | |
tags |
应该根据具体情况进行适合选取适合自己项目的方式
在本地使用mkdir创建目录,然后svn add/svn commit进行添加和提交,从而是的trunk/branches/tags目录能够得到管理和控制。
[root@platform ~]# svn co svn://192.168.163.129:3690/demo-repo
A demo-repo/first-svn-file
Checked out revision 1.
[root@platform ~]# cd demo-repo
[root@platform demo-repo]#
[root@platform demo-repo]# ls
first-svn-file
[root@platform demo-repo]# mkdir -p trunk branches tags
[root@platform demo-repo]# svn add trunk/ branches/ tags/
A trunk
A branches
A tags
[root@platform demo-repo]# svn commit -m "branches init"
Adding branches
Adding tags
Adding trunk
Committed revision 2.
[root@platform demo-repo]# ls
branches first-svn-file tags trunk
[root@platform demo-repo]#
同样也可以使用svn mkdir进行目录创建也能实现一样的效果,此处不再赘述。
首先创建操作的基础,我们在trunk下生成几个文件并进行svn管理
[root@platform trunk]# pwd
/root/demo-repo/trunk
[root@platform trunk]# svn log
------------------------------------------------------------------------ r2 | devuser1 | 2018-08-26 13:39:18 -0400 (Sun, 26 Aug 2018) | 1 line branches init ------------------------------------------------------------------------
[root@platform trunk]# touch trunk-file
[root@platform trunk]# svn add trunk-file
A trunk-file
[root@platform trunk]# svn commit -m "add file in trunk"
Adding trunk-file
Transmitting file data .
Committed revision 3.
[root@platform trunk]# svn log
------------------------------------------------------------------------ r2 | devuser1 | 2018-08-26 13:39:18 -0400 (Sun, 26 Aug 2018) | 1 line branches init ------------------------------------------------------------------------
[root@platform trunk]# svn update
Updating '.':
At revision 3.
[root@platform trunk]# svn log
------------------------------------------------------------------------ r3 | devuser1 | 2018-08-26 13:45:24 -0400 (Sun, 26 Aug 2018) | 1 line add file in trunk ------------------------------------------------------------------------
r2 | devuser1 | 2018-08-26 13:39:18 -0400 (Sun, 26 Aug 2018) | 1 line
branches init ------------------------------------------------------------------------
[root@platform trunk]#
主线版本中生成了一个文件,接下来我们进行分支开发,在此基础之上生成一个feature分支,然后在这个分支上进行进一步地开发。
[root@platform trunk]# svn copy svn://192.168.163.129:3690/demo-repo/trunk svn://192.168.163.129:3690/demo-repo/branches/feature_script -m "init feature_script branch"
Committed revision 4.
[root@platform trunk]# svn update
Updating '.':
At revision 4.
[root@platform trunk]# svn log
------------------------------------------------------------------------ r3 | devuser1 | 2018-08-26 13:45:24 -0400 (Sun, 26 Aug 2018) | 1 line add file in trunk ------------------------------------------------------------------------
r2 | devuser1 | 2018-08-26 13:39:18 -0400 (Sun, 26 Aug 2018) | 1 line
branches init ------------------------------------------------------------------------
[root@platform trunk]#
进入到新生成的分支中
[root@platform trunk]# cd ..
[root@platform demo-repo]# ls
branches first-svn-file tags trunk
[root@platform demo-repo]# cd branches/
[root@platform branches]# ls
[root@platform branches]# svn update
Updating '.':
A feature_script A feature_script/trunk-file
Updated to revision 4.
[root@platform branches]# ls
feature_script [root@platform branches]# cd feature_script/
[root@platform feature_script]# svn info Path: . Working Copy Root Path: /root/demo-repo URL: svn://192.168.163.129/demo-repo/branches/feature_script
Repository Root: svn://192.168.163.129/demo-repo
Repository UUID: 4fdba69f-3632-49f7-b5ba-d0491223c588
Revision: 4
Node Kind: directory
Schedule: normal
Last Changed Author: devuser1
Last Changed Rev: 4
Last Changed Date: 2018-08-26 13:50:49 -0400 (Sun, 26 Aug 2018)
[root@platform feature_script]# svn log ------------------------------------------------------------------------ r4 | devuser1 | 2018-08-26 13:50:49 -0400 (Sun, 26 Aug 2018) | 1 line init feature_script branch ------------------------------------------------------------------------
r3 | devuser1 | 2018-08-26 13:45:24 -0400 (Sun, 26 Aug 2018) | 1 line
add file in trunk ------------------------------------------------------------------------
r2 | devuser1 | 2018-08-26 13:39:18 -0400 (Sun, 26 Aug 2018) | 1 line
branches init ------------------------------------------------------------------------
[root@platform feature_script]#
在新的分支中添加一个文件
[root@platform feature_script]# pwd
/root/demo-repo/branches/feature_script
[root@platform feature_script]# ls
trunk-file
[root@platform feature_script]# touch feature_script.sh
[root@platform feature_script]# svn add feature_script.sh
A feature_script.sh
[root@platform feature_script]# svn commit -m "add feature_script.sh in branch"
Adding feature_script.sh
Transmitting file data .
Committed revision 5.
[root@platform feature_script]#
将刚刚修改的分支开发内容合并到主线trunk上
[root@platform trunk]# ls
trunk-file
[root@platform trunk]# svn merge svn://192.168.163.129:3690/demo-repo/branches/feature_script --- Merging r4 through r5 into '.': A feature_script.sh
--- Recording mergeinfo for merge of r4 through r5 into '.':
U .
[root@platform trunk]# ls
feature_script.sh trunk-file [root@platform trunk]# svn update Updating '.': At revision 5. [root@platform trunk]# svn log ------------------------------------------------------------------------ r3 | devuser1 | 2018-08-26 13:45:24 -0400 (Sun, 26 Aug 2018) | 1 line add file in trunk ------------------------------------------------------------------------
r2 | devuser1 | 2018-08-26 13:39:18 -0400 (Sun, 26 Aug 2018) | 1 line
branches init ------------------------------------------------------------------------
[root@platform trunk]#
对此次合并到主线上的内容进行发布,也是同样使用svn copy生成一个分支,当然结合svn的权限设定,在实践上建议tags设定为read-only更好。
[root@platform trunk]# svn copy svn://192.168.163.129:3690/demo-repo/trunk svn://192.168.163.129:3690/demo-repo/tags/release-script-1.0 -m "release for feature_script"
Committed revision 6.
[root@platform trunk]#
确认此次发布的内容
[root@platform trunk]# cd ../tags/
[root@platform tags]# svn update
Updating '.':
A release-script-1.0
A release-script-1.0/trunk-file
Updated to revision 6.
[root@platform tags]# svn log
------------------------------------------------------------------------ r6 | devuser1 | 2018-08-26 14:07:55 -0400 (Sun, 26 Aug 2018) | 1 line release for feature_script ------------------------------------------------------------------------
r2 | devuser1 | 2018-08-26 13:39:18 -0400 (Sun, 26 Aug 2018) | 1 line
branches init ------------------------------------------------------------------------
[root@platform tags]#
发现基于trunk的发布没有feature_script修改的内容,确认之后发现merge之后缺少commit的操作
[root@platform trunk]# ls
feature_script.sh trunk-file [root@platform trunk]# svn commit -m "commit for merge" Sending . Adding feature_script.sh
Committed revision 7.
[root@platform trunk]# svn log
------------------------------------------------------------------------ r7 | devuser1 | 2018-08-26 14:13:38 -0400 (Sun, 26 Aug 2018) | 1 line commit for merge ------------------------------------------------------------------------
r3 | devuser1 | 2018-08-26 13:45:24 -0400 (Sun, 26 Aug 2018) | 1 line
add file in trunk ------------------------------------------------------------------------
r2 | devuser1 | 2018-08-26 13:39:18 -0400 (Sun, 26 Aug 2018) | 1 line
branches init ------------------------------------------------------------------------
[root@platform trunk]#
追加发一版
[root@platform trunk]# svn copy svn://192.168.163.129:3690/demo-repo/trunk svn://192.168.163.129:3690/demo-repo/tags/release-script-1.1 -m "release for feature_script"
Committed revision 8.
[root@platform trunk]# cd ../tags/
[root@platform tags]# ls
release-script-1.0
[root@platform tags]# svn update
Updating '.':
A release-script-1.1
A release-script-1.1/feature_script.sh
A release-script-1.1/trunk-file
Updated to revision 8.
[root@platform tags]# cd release-script-1.1
[root@platform release-script-1.1]# ls
feature_script.sh trunk-file
[root@platform release-script-1.1]#