`

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

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics