`

SVN trunk branch concept and how to merge them(reposted)

阅读更多

需求一: 
有一个客户想对产品做定制,但是我们并不想修改原有的svn中trunk的代码。

方法: 
用svn建立一个新的branches,从这个branche做为一个新的起点来开发

代码
  1. svn copy svn://server/trunk svn://server/branches/ep -m "init ep"  

 

Tip: 
如果你的svn中以前没有branches这个的目录,只有trunk这个,你可以用

代码
  1. svn mkdir branches  

新建个目录

 

需求二: 
产品开发已经基本完成,并且通过很严格的测试,这时候我们就想发布给客户使用,发布我们的1.0版本

代码
  1. svn copy svn://server/trunk svn://server/tags/release-1.0 -m "1.0 released"  

 

咦,这个和branches有什么区别,好像啥区别也没有? 
是的,branches和tags是一样的,都是目录,只是我们不会对这个release-1.0的tag做修改了,不再提交了,如果提交那么就是branches

需求三: 
有一天,突然在trunk下的core中发现一个致命的bug,那么所有的branches一定也一样了,该怎么办?

代码
  1. svn -r 148:149 merge svn://server/trunk branches/ep  

其中148和149是两次修改的版本号。

SVN: Merging a Branch into Trunk

Added: April 11th, 2007 (tagged with: coding)

This is more for my benefit than anything else, but someone might find this useful.

Recently at work, I have taken on more responsibilities. Part of that includes branch control over a few web sites I work on. It took me a while to figure out how to manage everything properly and most of the stuff I found on the web wasn't much help so I will explain it here.

The source control program I am using is SVN and the source code is stored on a server with SSH access.

MERGE A BRANCH INTO TRUNK

  1. Check out a copy of trunk:
    svn co svn+ssh://server/path/to/trunk
  2. Check out a copy of the branch you are going to merge:
    svn co svn+ssh://server/path/to/branch/myBranch
  3. Change your current working directory to "myBranch"
  4. Find the revision "myBranch" began at:
    svn log --stop-on-copy
    This should display back to you the changes that have been made back to the point the branch was cut. Remember that number (should be rXXXX, where XXXX is the revision number).
  5. Change your current working directory to trunk
  6. Perform an SVN update:
    svn up
    This will update your copy of trunk to the most recent version, and tell you the revision you are at. Make note of that number as well (should say "At revision YYYY" where YYYY is the second number you need to remember).
  7. Now we can perform an SVN merge:
    svn merge -rXXXX:YYYY svn+ssh://server/path/to/branch/myBranch
    This will put all updates into your current working directory for trunk.
  8. Resolve any conflicts that arose during the merge
  9. Check in the results:
    svn ci -m "MERGE myProject myBranch [XXXX]:[YYYY] into trunk"

That is it. You have now merged "myBranch" with trunk.

BONUS: CUTTING A BRANCH

Cutting a branch is a lot easier than merging a branch. And as an added bonus, I will tell you how.

  1. Perform an SVN copy:
    svn copy svn+ssh://server/path/to/trunk svn+ssh://server/path/to/branch/newBranch -m "Cut branch: newBranch"

That's all there is to it.

Updated: June 18th, 2008

Steps 2-4 can be replaced by a remote log lookup:

svn log --stop-on-copy svn+ssh://server/path/to/branch



Every time I need to do this I try to use svn's --help which is only possible to decipher if you already know what to do. Then I spend too much time on the internet looking for the answer. And finally I break down and ask my tech lead. With much shame. I'm putting this up here so I least I'll know where to find it. Maybe you too.

In the directory of the branch:

svn merge -r 1001:1002 https://svn.dev.your/repo/trunk/src .

If you checked in some files in revision 1002, then what you're saying is that you only want the changes from that checkin with '-r 1001:1002' Which is followed by the url of the trunk (where the changes were checked in) and a '.' to say that you want to merge to the current directory. Use '--dry-run' if you want to see what would happen without actually screwing anything up. After the merge is successful, you now have some modified files in the branch you can check in.

Done and done.


Merge a branch back into the trunk (assuming that you have a working copy of the trunk, and that the branch was created in revision 250):

$ svn merge -r 250:HEAD http://svn.red-bean.com/repos/branches/my-branch
U  myproj/tiny.txt
U  myproj/thhgttg.txt
U  myproj/win.txt
U  myproj/flo.txt

If you branched at revision 23, and you want to merge changes on trunk into your branch, you could do this from inside the working copy of your branch:

$ svn merge -r 23:30 file:///tmp/repos/trunk/vendors
U  myproj/thhgttg.txt
…

To merge changes to a single file:

$ cd myproj
$ svn merge -r 30:31 thhgttg.txt 
U  thhgttg.txt

 

分享到:
评论

相关推荐

    SVN trunk, branch, tag merge 等的应用

    综上所述,理解和熟练运用SVN的trunk、branch、tag以及merge机制对于软件开发团队来说至关重要,它们是实现高效协同开发、保持代码整洁有序的基础。同时,使用像"admintools"这样的辅助工具可以进一步提升SVN的管理...

    4.1、SVN trunk(主线) branch(分支) tag(标记) 1

    本文将深入探讨 SVN 中的 trunk、branch 和 tag 三个核心概念,以及它们在实际开发场景中的应用。 首先,trunk(主干或主线)是项目的主要开发分支,代表了项目的最新稳定状态。新功能的开发通常在这个分支上进行,...

    SVN版本控制方案

    通过对SVN中Trunk、Branch、Tag的概念及使用方法的介绍,我们可以更好地理解如何高效地使用SVN来进行版本控制。遵循这些约定能够有效提升团队协作效率,减少代码冲突,确保项目的稳定性和可持续发展。

    svn merge简单操作

    svn commit -m "Merge changes from branch to trunk" ``` ##### 5. 修改主干内容 接下来,对 `trunk/examples1` 进行一些更改,并提交这些更改到服务器。 ```bash # 修改trunk/examples1的内容 # 提交更改到...

    SVN的标准目录结构:trunk、branches、tags

    当需要建立 branch 或 tag 时,可以使用 SVN 中的 copy 操作,例如,从 trunk 中 copy 到 branches 中,或者从 trunk 中 copy 到 tags 中。 权限控制 在 SVN 中,可以使用 authz 文件控制目录的访问权限。例如,...

    关于SVN下不同分支代码的Merge的透彻理解.zip

    多分支开发,Merge是一个绕不过的话题,不管是Git还是SVN,公司用的是SVN,之前对于SVN的Merge没有很好的研究,出了些状况,这个问题不解决,顺畅地进行多分支开发就是海市蜃楼,下定决心把这块给完全搞透,在百度上...

    svn trunk branches tags

    - **需求三**:如果在`trunk`中发现了一个致命bug(如在版本149),需要在所有分支上修复,可以使用`svn merge -r 148:149 svn://server/trunk branches/ep`命令,将`trunk`上的修复合并到`branches/ep`。...

    SVN 主干(trunk)、分支(branch )、标记(tag)

    资源中有 SVN 主干(trunk)、分支(branch )、标记(tag) 的详细解释,和作用 并带 SVN分支与合并 的详细操作文档(附图)。 SVN分支与合并的总结 1.分支(branche)的创建。 1、分支创建是建立在主干上的。 2、创建...

    SVNMerge源代码SVNMerge源代码

    SVNMerge是SVN的一个辅助工具,主要用于合并分支或解决代码冲突。在这个特定的上下文中,"SVNMerge源代码"指的是该工具的原始编程语言代码,可能是用C、C++或者Python等语言编写的,它允许开发者深入理解工具的工作...

    svn 合并、冲突及常用功能详解

    `svn merge`是Subversion(简称svn)中的关键命令,用于将一个分支或标记的修改合并到另一个分支。在版本控制系统中,合并是协同开发的核心操作,它允许团队成员同步各自的工作,避免代码冲突。以下是一些关于`svn ...

    cvs2svn-2.4.0.tar.gz

    The document you are currently reading contains a lot of general information about converting from CVS, and specifically how to use cvs2svn to convert your repository to Subversion. cvs2git....

    svn: This client is too old to work with

    项目中使用的是1.4.7,作为...Change the format of a Subversion working copy to that of SVN_VERSION. --skip-unknown-format : skip directories with unknown working copy format and continue the update

    VSS to SVN Tools

    VSS2SVN is a simple utility project that aims to help migrate the contents of a source safe database to subversion. To do that, VSS2SVN uses two key assemblies: The Microsoft sourcesafe interop ...

    SVN创建、合并与切换分支操作详解

    2. 使用SVN命令(如`svn copy`)或客户端工具来复制`trunk`到新的分支路径。 3. 更新你的工作副本到新创建的分支,此时你就可以在这个分支上进行独立的开发了。 ### 合并分支 合并分支的步骤: 1. 选择要合并的分支...

    SVN时,出现Failed to run the WC DB work queue的解决办法

    在使用Subversion(SVN)版本控制系统的过程中,有时会遇到“Failed to run the WC DB work queue”的错误提示,这通常是由于工作副本(Working Copy)数据库出现问题导致的。SVN使用SQLite3作为其本地数据库来存储...

    Chameleon_2.1svn_r2070_trunk_pkg.zip

    Chameleon 2.1svn_r2070_trunk_pkg.zip 是一个特定版本的Chameleon更新,包含了版本号为2.1的源代码控制版本(Subversion,简称svn)的修订版2070,从trunk分支提取。这个zip压缩包包含了一个名为"Chameleon_2.1svn_...

Global site tag (gtag.js) - Google Analytics