SVN部分分支

发布于 2024-08-12 03:52:20 字数 561 浏览 5 评论 0原文

我是 SVN 新手,所以这可能是一个简单的问题。

我们有一个带有一级目录的“主干”:

10 <-- documents
20 <-- source code, db scripts, ...
30 <-- documents
40 <-- referenced 3rd party library-es

我从“主干”创建了一个“开发”分支。 在“开发”中,我们更改源代码,并在测试后将其合并到“主干”。

问题在于目录“10”和“30”中存储了开发不需要的 *.doc 文件,因此要求“develop”分支没有这些目录。

解决方案仍然应该:

  1. 允许“develop”工作副本的根文件夹上的“svn update”,(20和40)
  2. 该更新不应重新创建 目录 10 和 30,
  3. 当然将“develop”合并到“trunk”不应删除“trunk”中的 10 或 30。

编辑: 我忘了提到“源代码”不仅在 20 中。还有引用的 dll-s 和构建脚本等也在第一级目录中,比如说 40。

I'm new to SVN so this could be an easy question.

We have a "trunk" with 1st level directories:

10 <-- documents
20 <-- source code, db scripts, ...
30 <-- documents
40 <-- referenced 3rd party library-es

I made a "develop" branch from the "trunk".
In "develop" we change our source code and after testing it we merge it to "trunk".

The problem in that in directories "10" and "30" are stored *.doc files that are not needed for development so it is REQUIRED that "develop" branch doesn't have those directories.

The solution should still:

  1. allow "svn update" on root folder of "develop" working copy, (20 and 40)
  2. that update should not re-create
    directories 10 and 30 and
  3. of course merging "develop" to "trunk" should NOT delete 10 or 30 in "trunk".

EDIT:
I forgot to mention that "source code" is not only in 20. There are referenced dll-s and build scripts etc. that are also on 1st level directory, lets say 40.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

掀纱窥君容 2024-08-19 03:52:20

如果我正确地阅读了你的问题,这是一个简单的问题,使用 svn copy 仅将所需的目录复制到分支中 - 基本上,是 Mike KushnerIvan Krechetov< 的答案的组合/em>.不过,我认为,在自己完成这些步骤之后可能会更容易理解,因此本文的其余部分将创建一个示例存储库并显示副本和合并。

我假设您使用的是“标准”存储库布局,该布局在顶层有三个子目录:trunkbranches>标签。并且您的 10203040 目录位于 trunk 下。换句话说:

trunk
    10
    20
    30
    40
branches
tags

并且,正如迈克指出的那样,您的目标将是拥有一个如下所示的结构:

trunk
    10
    20
    30
    40
branches
    sandbox
        20
        40
tags

从您的帖子中尚不清楚(至少在当前编辑中),但您可能有一个目录结构,其中 < em>10、20 等处于顶级水平。在这种情况下,您需要创建一个新的顶级目录,我将其称为dev,以便您的整个存储库如下所示:

10
20
30
40
dev
    20
    40

请注意,您无法创建dev 20以下。好吧,从身体上来说你可以,但是这样做几乎肯定会破坏你的构建。

好的,让我们看一个示例,在该示例中我们创建一个新存储库并在其中放入一些文件。您必须能够运行svnadmin命令(您应该能够执行此操作,除非您有一个偏执的系统管理员)。 ,选择一个临时目录,然后执行以下命令(我运行的是 Linux;如果您运行的是 Windows,命令将是相同的,但您需要在 REPO 变量中放置 Windows 特定的路径):

svnadmin create temp.repo
REPO="file://`pwd`/temp.repo"
svn co $REPO temp

因此 创建一个新的(空)存储库,并签出它的工作副本。第二行需要一些解释:它只是从当前目录创建存储库 URL。在我的工作区目录中,URL 如下所示:

file:///home/kgregory/Workspace/temp.repo

好的,现在您已经有了工作副本,让我们创建示例目录结构和一些文件:

cd temp
svn mkdir trunk
svn mkdir branches
svn mkdir tags
svn commit -m "standard repo structure"

pushd trunk
svn mkdir 10
svn mkdir 20
svn mkdir 30
svn mkdir 40
svn commit -m "example sub-project structure"

echo "this doesn't change" > 10/dontchange.txt
svn add 10/dontchange.txt
echo "this does change" > 20/change.txt
svn add 20/change.txt
svn status
svn commit -m "example files"
popd

此时,我们已经有了示例目录和其中的两个文件。这是 find 的输出,不包括 subversion 的隐藏目录:

temp, 531> find . | grep -v svn
.
./tags
./trunk
./trunk/10
./trunk/10/dontchange.txt
./trunk/30
./trunk/20
./trunk/20/change.txt
./trunk/40
./branches

下一步是创建沙箱目录,并复制其中的两个目录:

svn mkdir branches/sandbox
pushd branches/sandbox
svn copy ${REPO}/trunk/20 .
svn copy ${REPO}/trunk/40 .
svn commit -m "make development branch"
popd

这是重要的部分:我创建分支并复制到我的工作目录中,作为存储库的副本。通常,您只需使用带有两个存储库参数的 svn copy 将 trunk 复制到 branches 的子级中。这在这里不起作用,因为我们只想要 trunk 的两个子节点。

完成此操作后,我的工作副本如下所示:

temp, 539> find . | grep -v svn
.
./tags
./trunk
./trunk/10
./trunk/10/dontchange.txt
./trunk/30
./trunk/20
./trunk/20/change.txt
./trunk/40
./branches
./branches/sandbox
./branches/sandbox/20
./branches/sandbox/20/change.txt
./branches/sandbox/40

此时,您通常会将开发分支签入新的工作目录并在那里工作。所以我会这样做(在cd回到我的工作区目录之后):

svn co ${REPO}/branches/sandbox sandbox
cd sandbox

现在进行一些更改:

vi 20/change.txt
svn commit -m "changed on branch"

好的,现在是时候合并回主干了。因此,返回工作区,仅检查主干:

svn co ${REPO}/trunk trunk
cd trunk

并从沙箱中合并。合并过程在 中描述Subversion 文档

svn merge -r 4:5 ${REPO}/branches/sandbox
svn status

最后一个命令应该显示只有文件 20/change.txt 受到合并的影响。由于您没有将 10 或 30 个目录复制到分支中,因此合并不会触及它们。

If I read your question correctly, this is a simple matter of using svn copy to copy only the desired directories into a branch -- basically, a combination of answers from Mike Kushner and Ivan Krechetov. I think, however, it might be easier to understand after running through the steps yourself, so the rest of this post will create a sample repository and show the copies and merges.

I'm going to assume that you're using the "standard" repository layout, which at the top level has three sub-directories, trunk, branches, and tags. And that your 10, 20, 30, and 40 directories are under trunk. In other words:

trunk
    10
    20
    30
    40
branches
tags

And, as Mike pointed out, your goal will be to have a structure that looks like this:

trunk
    10
    20
    30
    40
branches
    sandbox
        20
        40
tags

It's unclear from your posting (at least as-of the current edit), but you may have a directory structure in which 10, 20, et al are at the top level. In this case, you'll need to create a new top-level directory, which I'll call dev, so that your overall repository looks like the following:

10
20
30
40
dev
    20
    40

Note that you cannot create dev under 20. Well, physically you can, but you're almost guaranteed to break your build when doing so.

OK, so let's walk through an example, in which we create a new repository and put some files in it. You have to be able to run the svnadmin command (which you should be able to do, unless you have a paranoid sysadmin). So pick a temporary directory, and execute the following commands (I'm running Linux; if you're running Windows the commands will be the same, but you'll need to put a Windows-specific path in the REPO variable):

svnadmin create temp.repo
REPO="file://`pwd`/temp.repo"
svn co $REPO temp

This creates a new (empty) repository, and checks out a working copy of it. The second line needs some explanation: it simply creates the repository URL from the current directory. In my workspace directory, the URL looks like this:

file:///home/kgregory/Workspace/temp.repo

OK, now that you've got a working copy, let's create the sample directory structure and some files:

cd temp
svn mkdir trunk
svn mkdir branches
svn mkdir tags
svn commit -m "standard repo structure"

pushd trunk
svn mkdir 10
svn mkdir 20
svn mkdir 30
svn mkdir 40
svn commit -m "example sub-project structure"

echo "this doesn't change" > 10/dontchange.txt
svn add 10/dontchange.txt
echo "this does change" > 20/change.txt
svn add 20/change.txt
svn status
svn commit -m "example files"
popd

At this point we have the sample directories and two files in them. Here's the output from find, excluding subversion's hidden directories:

temp, 531> find . | grep -v svn
.
./tags
./trunk
./trunk/10
./trunk/10/dontchange.txt
./trunk/30
./trunk/20
./trunk/20/change.txt
./trunk/40
./branches

Next step is to create the sandbox directory, and make copies of the two directories that are going to be in it:

svn mkdir branches/sandbox
pushd branches/sandbox
svn copy ${REPO}/trunk/20 .
svn copy ${REPO}/trunk/40 .
svn commit -m "make development branch"
popd

This is the important part: I creating the branch and copies in my working directory, as a copy from the repository. Normally, you just copy trunk into a child of branches, using svn copy with two repository arguments. That doesn't work here, because we want only two children of trunk.

After doing this, my working copy looks like this:

temp, 539> find . | grep -v svn
.
./tags
./trunk
./trunk/10
./trunk/10/dontchange.txt
./trunk/30
./trunk/20
./trunk/20/change.txt
./trunk/40
./branches
./branches/sandbox
./branches/sandbox/20
./branches/sandbox/20/change.txt
./branches/sandbox/40

At this point, you'd normally check out the development branch into a new working directory and work there. So I'll do that (after a cd back to my Workspace directory):

svn co ${REPO}/branches/sandbox sandbox
cd sandbox

And now make some changes:

vi 20/change.txt
svn commit -m "changed on branch"

OK, now it's time to merge back to the trunk. So go back to the workspace, and check out just the trunk:

svn co ${REPO}/trunk trunk
cd trunk

And merge from the sandbox. The merge process is described in the Subversion docs:

svn merge -r 4:5 ${REPO}/branches/sandbox
svn status

That last command should show you that only the file 20/change.txt was affected by the merge. Since you didn't copy the 10 or 30 directories into the branch, they won't be touched by the merge.

单挑你×的.吻 2024-08-19 03:52:20

你想要做的是在你的 svn 树中的某个地方创建一个“20”的副本,你可以与它来回合并。一个常见的结构是

repo
---> trunk
    ---> 10 
    ---> 20
    ---> 30
---> branches
    ---> sandboxes
        ---> develop <branch of 20>
---> tags

当你想要更新“develop”时,你要么在沙箱下创建一个新的“20”分支,要么从20执行合并到develop。当您希望“开发”中的更改回到您的主干时,您可以以另一种方式合并。您的开发人员应该查看“develop”的副本(或基于“develop”创建自己的分支)

What you want to do is create a copy of "20" somewhere in your svn tree, which you can merge back and forth with. A common structure is

repo
---> trunk
    ---> 10 
    ---> 20
    ---> 30
---> branches
    ---> sandboxes
        ---> develop <branch of 20>
---> tags

When you want to update "develop", you either create a new branch of "20" under sandboxes or perform a merge from 20 to develop. When you want the changes in "develop" back in your trunk you merge the other way. Your developers should check out a copy of "develop" (or create their own branches based on "develop")

迟到的我 2024-08-19 03:52:20

据我所知,您无法使用当前拥有的存储库结构来做到这一点。

我建议你重组你的存储库,所以 10 & 20、40 和其他与代码相关的资产将移至新的一级文件夹下。这样您就可以避免这种情况,并简化获取代码相关资产的过程。

afaik you can't do it with the repository structure you currently have.

I suggest you restructure your repository, so 10 & 20, 40 & the other code related assets are moved under a new 1st level folder. This way you avoid this situation, and simplify being able to grab just the code related assets.

简单气质女生网名 2024-08-19 03:52:20

理想情况下,您应该在较低级别分支。即分支 20 不是主干。这样你就只对应该分支的内容进行分支。即你想要分支。

Ideally then you should branch at a lower level. i.e. branch 20 not trunk. That way you're only branching the content that should be branched. i.e. that you want branched.

冬天旳寂寞 2024-08-19 03:52:20

您可以通过仅使工作副本的源代码子目录指向其分支来实现此目的。

svn cp http://example.com/svnrepo/trunk/source_code http://example.com/svnrepo/branches/development/source_code

cd ./source_code
svn sw http://example.com/svnrepo/branches/development/source_code

进行更改,提交。然后,让我们合并到主干:

svn sw http://example.com/svnrepo/trunk/source_code
cd ..
svn merge -r [start_rev]:HEAD http://example.com/svnrepo/branches/development/source_code ./source_code

检查以确保一切正常:

svn diff | less

然后提交。
完毕。

You can achieve that by making only the source code subdirectory of your working copy point to its branch.

svn cp http://example.com/svnrepo/trunk/source_code http://example.com/svnrepo/branches/development/source_code

cd ./source_code
svn sw http://example.com/svnrepo/branches/development/source_code

Do the changes, commit. Then, let's merge to the trunk:

svn sw http://example.com/svnrepo/trunk/source_code
cd ..
svn merge -r [start_rev]:HEAD http://example.com/svnrepo/branches/development/source_code ./source_code

Review to make sure all's fine:

svn diff | less

And then commit.
Done.

浮世清欢 2024-08-19 03:52:20

我们这样做:

-repo: Assemblies
--SomeAssembly
---Current
---v1.0
---v1.1
-repo: Source
--trunk
---Code
---Assemblies (external from Assemblies repo)
--branches
---v1.0
----Code
----Assemblies (external from Assemblies repo)
--Documents

在这个例子中,第 3 方程序集有自己的存储库。这样您就不会在每个分支和主干中维护不同的版本。顺便说一句,任何程序集的最新版本都会复制到每个程序集的“当前”文件夹中。这允许更新程序集,而无需更新所有项目中的引用。这在您的领域可能不是问题,但在我们的领域却是一个很大的痛苦。

另请注意,文档在层次结构中与主干和分支处于同一级别。这样这些文件就不会重复。如果这不是一个选项,那么它们也可以外部化,这将允许它们存在于主干和分支中,而无需单独进行源控制。

We do something like this:

-repo: Assemblies
--SomeAssembly
---Current
---v1.0
---v1.1
-repo: Source
--trunk
---Code
---Assemblies (external from Assemblies repo)
--branches
---v1.0
----Code
----Assemblies (external from Assemblies repo)
--Documents

In this example, the 3rd party assemblies have their own repository. This way you aren't maintaining different versions in each branch and trunk. As a side note, the latest version of any assembly is duplicated in the "Current" folder for each assembly. This allows the assembly to be updated without having to update references in all your projects. This may not be an issue in your domain, but it was a big pain in ours.

Also note that the documents are at the same level in the hierarchy as trunk and the branches. This way those files don't get duplicated. If this is not an option, those can be externaled as well, which would allow them to be present in the trunk and branches without being separately source controlled.

夜未央樱花落 2024-08-19 03:52:20

您构建项目的方式以及文档目录限制并不适合开箱即用的 SVN 模型。

一些想法:

  • 将文档目录移到主干之外,并将其添加为 svn:external
  • 将文档目录移到主干之外,并使用构建脚本将主干和文档目录合并
  • (而不是使用脚本)直接 svn merge),并让脚本强制执行规则

The way you structure your project, along with the docs dir restrictions, doesn't fit with SVN's model out of the box.

Some ideas:

  • Move the docs dir outside trunk, and add it as an svn:external
  • Move the docs dir outside trunk, and have a build script combine trunk and the docs dir
  • Merge using a script (instead of a direct svn merge), and have the script enforce the rules
绝不放开 2024-08-19 03:52:20

从你的评论来看:

我们希望防止修改 10 和 30 中的文档。它们应该只在主干中修改。

您是否考虑过在 svn:externals 中使用10 和 30 的 code>develop 分支?使用 ^/ 从根进行相对引用可能是一个好方法。

因此,虽然 10、20、30 和 40 可以在分支上访问,但 10 和 30 仍然可以从主干引用。然后,您可以根据需要定义您的授权需求。

仓库
..->后备箱
......-> 10
......-> 20
......-> 30
......-> 40
..->分支机构
......->开发
……-> 10(位于主干上,svn:externals ^/trunk/10)
……-> 20(位于分支上,合并到主干)
……-> 30(位于主干上,svn:externals ^/trunk/30)
……-> 40(位于分支上,合并到主干)

From your comment:

We want to prevent modification of documents in 10 and 30. They should be modified only in the trunk.

Have you considered using svn:externals in the develop branch for 10 and 30? Relative referencing from root using ^/ would probably be a good approach.

So whilst 10, 20, 30 and 40 would be accessible on the branch, 10 and 30 are still referenced from trunk. You can then define your authorization needs as required.

repo
..-> trunk
....-> 10
....-> 20
....-> 30
....-> 40
..-> branches
....-> develop
......-> 10 (lives on trunk, svn:externals ^/trunk/10)
......-> 20 (lives on branch, merge to trunk)
......-> 30 (lives on trunk, svn:externals ^/trunk/30)
......-> 40 (lives on branch, merge to trunk)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文