当前位置: 代码迷 >> CVS/SVN >>
  详细解决方案

热度:7845   发布时间:2013-02-26 00:00:00.0
如何合并svn分支到主干上

转:http://blog.csdn.net/tanlijun37/article/details/5481342

1:进入主干的svn目录
?
?2:首先查询出创建分支的开始版本


?命令:svn -q --stop-on-copy 分支URL,这条命令会查询出自创建分支以后
?分支上的所有修改,最下面的那个版本号就是我们要找的版本号.


?示例:
??svn log -q --stop-on-copy svn://192.168.1.177/tags/beta_2009_12_24
?
?3:使用svn merge命令合并分支。
?
?命令:
?? svn -r 分支版本号:HEAD 分支的URL
??
解释:HEAD为当前主干上的最新版本

?

示例:
?? svn merge -r 12:HEAD svn://192.168.1.177/tags/beta_2009_12_24

?

4: 使用svn st | grep "C????? "查找合并时的冲突文件,手工解决冲突

?

5:使用svn commit -m "" 提示合并后的版本

--------------------------------------------------------------------------------------------------------

?

详细说明svn分支与合并,以及实例

张映 发表于 2010-10-24

分类目录: 服务器相关

一,svn分支与合并有什么用?

作程序的,对svn在熟悉不过了,但对svn分支熟悉的,我想并不多。因为一般情况下,是用不着svn分支的,其实也没有那个必要。下面我例举几个需要用到svn分支的情况:

1,比较大的项目。比较大的项目,一般情况下会分成几个阶段来完。好比什么五年计划。到了某个阶段时,我建立一个分支,当个备份。万一将来开发下个阶段东西的时候,出现致命错误的时候,我还能把这个分支拿出来接着用。

2,项目要开发新的东西,但是又不想和主干冲突,建立一个分支,单独做为一个开发分支。这样做也是为了责任明确。如果出了问题也好有所查证。

二,创建svn分支

在说创建分支前,关于svn的安装和配置,请参考linux svn安装和配置,不结合apache

1,创建一个代码文件夹main

[root@BlackGhost repos]# pwd
/home/zhangy/checkout/repos
[root@BlackGhost repos]# svn add ./main
A???????? main
A???????? main/test.php
[root@BlackGhost repos]# svn commit ./main -m "test"
Adding???????? main
Adding???????? main/test.php
Transmitting file data .
Committed revision 5.

2,创建分支

[root@BlackGhost repos]# svn copy svn://127.0.0.1/repos/main svn://127.0.0.1/repos/branch -m "test"

Committed revision 6.

3,查看分支情况

[root@BlackGhost repos]# svn log -v ./branch/test.php
------------------------------------------------------------------------
r6 | zhangy | 2010-10-24 19:59:35 +0800 (Sun, 24 Oct 2010) | 1 line
Changed paths:
A /branch (from /main:5)

test
------------------------------------------------------------------------
r5 | zhangy | 2010-10-24 19:53:20 +0800 (Sun, 24 Oct 2010) | 1 line
Changed paths:
A /main
A /main/test.php

test
------------------------------------------------------------------------

4,注间事项:

a),创建分支,只能在同一个仓库内进行,跨仓库是不行的。会提示svn: No repository found in 'svn://127.0.0.1'

b),创建分支时,注意加上注释,不然会报以下错误。

[root@BlackGhost repos]# svn cp svn://127.0.0.1/repos/main svn://127.0.0.1/repos/branch
svn: Could not use external editor to fetch log message; consider setting the $SVN_EDITOR environment variable or using the --message (-m) or --file (-F) options
svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set, and no 'editor-cmd' run-time configuration option was found

三,合并分支

下面讲一个例子,来说明怎么合并分支。我觉得通过例子,最能让人学到东西了,我在我的博文一在强调这一点。

1,修改main中的文件提交到svn服务器端,这样main的代码就和branch分支的代码就不一样了。

2,把main文件中的文件同步到分支中branch中

[root@BlackGhost branch]# pwd????? //是否在分支的文件夹中/home/zhangy/checkout/repos/branch/**把main的修改同步到branch分支中如果是指定版本的可以svn merge -r 9:10 svn://127.0.0.1/repos/main*/[root@BlackGhost branch]# svn merge svn://127.0.0.1/repos/main????????????--- Merging r6 through r8 into '.':???? //更新到第8个版本U??? test.php[root@BlackGhost branch]# svn log -v test.php?? //查看test.php,从下面我们可以看出,分支版本还是没有变为什么呢?------------------------------------------------------------------------r6 | zhangy | 2010-10-24 19:59:35 +0800 (Sun, 24 Oct 2010) | 1 lineChanged paths: A /branch (from /main:5)test------------------------------------------------------------------------r5 | zhangy | 2010-10-24 19:53:20 +0800 (Sun, 24 Oct 2010) | 1 lineChanged paths: A /main A /main/test.phptest------------------------------------------------------------------------[root@BlackGhost branch]# svn commit -m "test"?? //提交Sending??????? .Sending??????? test.phpTransmitting file data .Committed revision 9.[root@BlackGhost branch]# svn log -v test.php?? //是没因为没有提交,提交后会产生一个新的版本------------------------------------------------------------------------r9 | zhangy | 2010-10-24 20:52:22 +0800 (Sun, 24 Oct 2010) | 1 lineChanged paths: M /branch M /branch/test.phptest------------------------------------------------------------------------r6 | zhangy | 2010-10-24 19:59:35 +0800 (Sun, 24 Oct 2010) | 1 lineChanged paths: A /branch (from /main:5)test------------------------------------------------------------------------r5 | zhangy | 2010-10-24 19:53:20 +0800 (Sun, 24 Oct 2010) | 1 lineChanged paths: A /main A /main/test.phptest------------------------------------------------------------------------

到这儿合并基本上就结束了。

3,上面说的是将主干的文件同步到分支中去,把分支的内容同步步主干也是一样的,倒过来就行了。

4,全并的时候,有可能会冲突的,看下面

[root@BlackGhost main]# svn merge svn://127.0.0.1/repos/branchConflict discovered in 'test.php'.??? //提示有冲突Select: (p) postpone, (df) diff-full, (e) edit,?????? //在这里让你选择处理方式(mc) mine-conflict, (tc) theirs-conflict,(s) show all options: p--- Merging r7 through r12 into 'test.php':C??? test.phpSummary of conflicts:Text conflicts: 1?????? //虽然有冲突,但是还是可以同步了,也说明同步成功了。--- /tmp/tempfile.2.tmp?? ?Sun Oct 24 21:02:11 2010+++ .svn/tmp/test.php.tmp?? ?Sun Oct 24 21:02:11 2010@@ -0,0 +1,9 @@+<<<<<<< .working+asdfadfadfadf+111111111111111+=======+asdfadfadfadf+111111111111111+222222222222++>>>>>>> .merge-right.r12
  相关解决方案