如何将两个独立但相似的代码库合并成一个SVN代表

如何将两个独立但相似的代码库合并成一个SVN代表

本文介绍了如何将两个独立但相似的代码库合并成一个SVN代表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在www.example.com上有

/ var / www / cool_codebase并且我有

/ var / www / cool_codebase on www.example.net



这些代码库适用于运行在不同服务器上的相同Web应用程序。在代码库(客户端特定的位和bobs等)之间有一些专业化 - 但不是太多。一个代码库具有另一个不具有的文件,反之亦然。



我已经将每个代码库下载到本地主机,我的问题是:

如何将这两个文件夹合并到一个文件夹中,然后将其作为一个宏伟的统一代码库提交到我的SVN?



我应该将每个代码库放入自己的SVN回购,然后合并这些单独的回购?或者,我可以在 SVN之前合并之前的代码库然后然后将其提交给SVN?



任何想法或帮助将不胜感激。



我应该补充一点,最终结果将是我们可以部署到www.example.com的一个宏伟统一代码库 .com和www.example.net没有打嗝。



(PS。是的,我意识到无论我做什么,我都必须编辑一些文件并制作编程通用等等,我不介意这一点,我只是在寻找方法来自动化或半自动化整个事情。)

解决方案 在将它们提交给svn之后合并代码库具有以下优点:您可以随后访问其历史记录:您将能够看到代码的哪些部分来自来自.net的.com版本,以及在将两者结合的过程中发生了哪些变化。



一种方法是:


  1. 将.com代码库导入到新的存储库中作为中继。 从该干线创建一个分支: svn cp svn:// repo / trunk svn:// repo / branches / net

  2. 签出分支,拷贝.net代码, code> svn add 和删除,以便该分支完全包含.net版本。提交。

  3. 检查中继和 svn merge ^ / branches / net。

  4. 仔细检查 svn diff 的输出,然后编辑trunk结帐,以便它成为您的统一代码库。



  5. 步骤5的难度将取决于具体的代码库。



    如果碰巧可以访问一个较老的共同的祖先版本,从这两个代码库派生出来,那么你应该在步骤1中检查该版本,然后在步骤4之前检查.com版本。这使得svn可以在第5步做一个自动的3-way merge,可能为你节省大量的手工工作。



    不管你做什么,都可以手动编辑的文件将需要。使用一个良好的交互式合并工具,比如,这是一个伟大的替代平原 svn diff 用于上述第5步。



    请注意,meld能够a)比较整个目录树和b )一次比较和编辑三个版本。所以你可以把它指向一个包含.com代码的目录,其中一个包含.net代码,而你的工作目录可以并排查看所有三个版本。


    I have

    /var/www/cool_codebase on www.example.com AND I have

    /var/www/cool_codebase on www.example.net

    The codebases are for the same web app running on different servers. There is some specialisation between the codebases (client-specific bits and bobs etc) - but not too much. One codebase has files that the other doesn't and vice-versa. Some bits of programming are different too.

    I have downloaded each codebase to my localhost and my question is:

    How can I merge these two folders into one folder and then commit it as one "grand unified codebase" into my SVN?

    Should I put each codebase into its own SVN repo, and then merge these separate repos? Or can I merge the codebases before SVN - using some linux command for example - and then commit it to SVN?

    Any ideas or help would be greatly appreciated.

    I should add that the end result would be ONE "grand unified codebase" that we can deploy to both www.example.com and www.example.net with no hiccups.

    (PS. Yes, I realise that whatever I do I'll have to edit some of the files and make the programming "generic" and so on. I don't mind this. I'm simply looking for ways to automate or semi-automate the whole thing.)

    解决方案

    Merging the code bases after committing them to svn has the advantage that you have access to their history afterwards: You'll be able to see which parts of the code came from the ".com" version, which from the ".net", and what changes were made in the process of combining the two.

    One way to do this:

    1. Import the ".com" code base into a new repository as trunk.
    2. Create a branch from that trunk: svn cp svn://repo/trunk svn://repo/branches/net
    3. Check out the branch, copy in the ".net" code, do svn add and remove as needed so that the branch contains exactly the .net version. Commit that.
    4. Check out the trunk and svn merge ^/branches/net .
    5. Very carefully review the output of svn diff, and edit the trunk checkout so it becomes your grand unified codebase.

    How difficult step 5 is will depend very much on the specific code bases.

    If you happen to have access to an older "common ancestor" version, from which both of the code bases are derived, then you should check that version in at step 1 instead, and then check in the ".com" version to the trunk before step 4. This enables svn to do an automatic "3-way merge" at step 5, potentially saving you a bunch of manual work.

    Whatever way you do it, some manual editing of files will be needed. That goes a lot easier with a good interactive merge tool, such as meld, which is also a great alternative to plain svn diff for step 5 above.

    Note that meld has the ability to a) compare entire directory trees and b) compare and edit three versions at once. So you can point it at a a directory containing the ".com" code, one containing the ".net" code, and your working directory to see all three versions side by side.

    这篇关于如何将两个独立但相似的代码库合并成一个SVN代表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 14:34