在SVN中,如何维护会被2个或更多项目更改的公共代码库?
这个问题在某种意义上与“共享共同点的最佳方式”相关代码”,但本例中情况略有不同。
我现在正在为一个项目编写一个应用程序,比如 A。它尚未完成,现在将启动一个新项目 B,它基本上是 A 的复制品,但带有附加组件。由于这两个项目都未完成,我很可能会在 A 中进行修复,然后将其带到 B 中;也许还有 B 中的增强功能,我也想将其移植到 A 中。
针对我的情况,我应该如何使用 SVN?
This question is in a sense related to "Best way to share common code", but the situation is slightly different in this case.
I am now coding an application, say A, for a project. It is unfinished and now a new project B, will be started and is basically a replicate of A with add-ons. As both projects are unfinished, it is likely that I will have fixes in A which I need to bring over to B; and perhaps enhancements in B which I would like to port to A too.
How should I use SVN for my situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
理想情况下,您应该尽量不要在进行中拥有两个非常相似的项目的副本。这会引发各种麻烦。正如您所描述的那样,尝试使它们保持同步需要不断地来回合并,这很困难且容易出错。
更好的是,以这样的方式构建您的项目,以便共享部分可以真正共享。也许把它变成一个图书馆。或者,也许,让它们成为一个大项目,有两种不同的构建 - 一种用于构建 A,另一种用于构建 B。
Ideally, you should try not to have two copies of very similar projects in progress. That is a recipe for all kinds of trouble; trying to keep them in sync as you describe would require constantly merging back and forth, which is difficult and error prone.
Better, to build your project in such a way so that the shared parts can really be shared. Perhaps make it a library. Or perhaps, make them both one big project, with two different builds - one to build A, and one for B.
如果它们真的那么相似,我只需在项目 A 的存储库中为项目 B 创建一个分支,然后根据需要进行合并。
否则,将公共代码提取到自己的新存储库中,并使用 svn:externals 在每个项目中引用它。
If they are really that similar, I would just create a branch in Project A's repo for Project B, and then merge as needed.
Otherwise, extract the common code into its own new repo, and use
svn:externals
to reference it in each project.听起来您想要在您的存储库中建立一个新分支,您可以在其中开发新内容或维护旧内容。 (您必须选择是否使用 stdnard trunk/branches/tags 布局)。这可能是最简单的方法。
如果您想分离代码,您的选择是:
svn:externals
到具有公共代码的第三个存储库,其中您有 A 和 B 的分支(如果需要),因此您可以轻松地在两者之间合并。如果代码在两个项目中独立更改,则尝试在每个存储库中保留单独的版本将导致灾难。根本不支持不同存储库之间的合并,所以不要去那里。 (相信我。我去过那里。)
It sounds like you want a new branch in your repo, where you either develop new stuff, or maintain the old. (You have to choose if you use the stadnard trunk/branches/tags layout). That is probably the easiest way to do this.
If you want to separate code, your options are:
svn:externals
to a third repo with the common code, where you have branches for A and B (if necessary) so you can easily merge betwen both.Trying to keep separate versions in each repo is a recipe for disaster if that code changes independently in both projects. Merging between different repos are not supported at all, so don't go there. (Trust me. I've been there.)