使用 hg 将不同的项目与存储库合并到一个解决方案中?

发布于 2024-10-25 22:12:27 字数 835 浏览 4 评论 0原文

我在 Visual Studio 2010 中启动了两个不同的项目,每个项目都有自己的 hg 存储库。

后来我决定这两个项目属于一个解决方案,因此属于一个 hg 存储库。

新的解决方案具有以下文件结构:

SolutionFolder
   |---.hg
   +---Lib
   |    ∟ dlls
   +---Source
   |    ∟ Project_A
   |      ∟--.hg  
   |    ∟ Project_B
   |      ∟--.hg
   +---OverarchingSolution.sln

有没有一种方法可以 Project_AProject_B 的变更集合并到解决方案文件夹的存储库中吗?

从而导致:

SolutionFolder
   |---.hg
   +---Lib
   |    ∟ dlls
   +---Source
   |    ∟ Project_A
   |    ∟ Project_B
   +---OverarchingSolution.sln

Project_AProject_B 的所有变更集都登陆到 SolutionFolder 的存储库中?

I started two disparate projects in Visual Studio 2010, each with their own hg repository.

Later I decided that the two projects belonged under one solution, and thus one hg repository.

The new solution the following file structure:

SolutionFolder
   |---.hg
   +---Lib
   |    ∟ dlls
   +---Source
   |    ∟ Project_A
   |      ∟--.hg  
   |    ∟ Project_B
   |      ∟--.hg
   +---OverarchingSolution.sln

Is there a way that I can merge Project_A's and Project_B's changesets into the solution folder's repository?

Thus resulting in:

SolutionFolder
   |---.hg
   +---Lib
   |    ∟ dlls
   +---Source
   |    ∟ Project_A
   |    ∟ Project_B
   +---OverarchingSolution.sln

With all of the changesets from Project_A's and Project_B's landing in the SolutionFolder's repository?

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

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

发布评论

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

评论(3

蓝颜夕 2024-11-01 22:12:58

如果您同意更改历史记录(即:使该项目的其他人的克隆无效),您可以使用“转换”扩展。

创建文本文件,我们将其命名为 rename-map-a.txt 其中这一行:

rename . Source/Project_A

然后进入 Source 并运行:

hg convert --filemap rename-map-a.txt Project_A new-Project_A

对 B 重复相同的过程,以便现在你有了:

SolutionFolder
   |---.hg
   +---Lib
   |    ∟ dlls
   +---Source
   |    ∟ Project_A
   |      ∟--.hg  
   |    ∟ Project_B
   |      ∟--.hg
   |    ∟ new-Project_A
   |      ∟--.hg  
   |    ∟ new-Project_B
   |      ∟--.hg
   +---OverarchingSolution.sln

然后进入 SolutionFolder 并运行这些命令:

hg init   # creates a new, empty repo
hg pull Source/new-Project_A   # pulls in changesets from A
hg pull --force Source/new-Project_B   # pulls in changesets from A

如果有效,你可以删除(或者更好地移动到某个地方来备份这些目录:

SolutionFolder/Source/Project_A/.hg
SolutionFolder/Source/Project_B/.hg
SolutionFolder/Source/new-Project_A
SolutionFilder/Source/new-Project_B

让你得到你问题中的目标,话虽如此,请参阅我的其他答案,了解我认为更好的想法。

If you're okay with altering history (ie: invalidating everyone else's clones of this project) you can use the 'convert' extension.

Create text file, we'll call it rename-map-a.txt this line in it:

rename . Source/Project_A

Then go into Source and run:

hg convert --filemap rename-map-a.txt Project_A new-Project_A

Repeat the same process for B so that now you have:

SolutionFolder
   |---.hg
   +---Lib
   |    ∟ dlls
   +---Source
   |    ∟ Project_A
   |      ∟--.hg  
   |    ∟ Project_B
   |      ∟--.hg
   |    ∟ new-Project_A
   |      ∟--.hg  
   |    ∟ new-Project_B
   |      ∟--.hg
   +---OverarchingSolution.sln

Then go into SolutionFolder and run these commands:

hg init   # creates a new, empty repo
hg pull Source/new-Project_A   # pulls in changesets from A
hg pull --force Source/new-Project_B   # pulls in changesets from A

If that worked you can remove (or better move somewhere for backup these directories:

SolutionFolder/Source/Project_A/.hg
SolutionFolder/Source/Project_B/.hg
SolutionFolder/Source/new-Project_A
SolutionFilder/Source/new-Project_B

leaving you with exactly what you have as the goal in your question, and with all history and everything tracked. That said, see my other answer for what I think is a better idea.

荭秂 2024-11-01 22:12:58

实现此目的的一种方法是使用 从不相关的存储库中提取 hg pull -f 。
这将导致存储库具有多个根。
您仍然会拥有两个存储库的历史记录,这些历史记录将由存储库中的两条开发线表示。

这里唯一的技巧是使目录结构正确。您希望合并存储库的根目录与组合存储库的根目录相匹配。

因此,对于您的情况,我会想象这样的事情:

    C:\> move SolutionFolder\Source\Project_A Temp_Project_A
    C:\> cd Temp_Project_A
    C:\Temp_Project_A> mkdir Source\Project_A
    C:\Temp_Project_A> hg rename * Source\Project_A
    C:\Temp_Project_A> hg ci -m "moved all Project_A files down in preparation for combining repos"
    C:\Temp_Project_A> cd ..\SolutionFolder
    C:\SolutionFolder> hg pull -f ..\Temp_Project_A
    C:\SolutionFolder> hg merge
    C:\SolutionFolder> hg ci -m "merged Project_A repo into main one"

    (and similar for Project B)

查看 Mercurial Wiki

这是一个具有实际输出的通用示例:

    C:\>hg ini repoA

    C:\>hg ini repoB

    C:\>cd repoA

    C:\repoA>echo FOO > foo.txt

    C:\repoA>hg add
    adding foo.txt

    C:\repoA>hg ci -m "added foo in repo A"

    C:\repoA>cd ..\repoB

    C:\repoB>echo BAR > bar.txt

    C:\repoB>hg add
    adding bar.txt

    C:\repoB>hg ci -m "added bar in repo B"

    C:\repoB>cd ..

    C:\>hg clone repoA combinedRepo
    updating to branch default
    1 files updated, 0 files merged, 0 files removed, 0 files unresolved

    C:\>cd combinedRepo

    C:\combinedRepo>hg pull -f ..\repoB
    pulling from ..\repoB
    searching for changes
    warning: repository is unrelated
    adding changesets
    adding manifests
    adding file changes
    added 1 changesets with 1 changes to 1 files (+1 heads)
    (run 'hg heads' to see heads, 'hg merge' to merge)

    C:\combinedRepo>hg merge
    1 files updated, 0 files merged, 0 files removed, 0 files unresolved
    (branch merge, don't forget to commit)

    C:\combinedRepo>hg ci -m "merged repoB into repoA"

    C:\combinedRepo>hg gl
    @    changeset:   2:3d08641554c5
    |\   tag:         tip
    | |  parent:      0:bc6a6ad6a3e5
    | |  parent:      1:54dc5af30c7a
    | |  user:        j.w.
    | |  date:        Fri Mar 25 10:12:32 2011 -0700
    | |  summary:     merged repoB into repoA
    | |
    | o  changeset:   1:54dc5af30c7a
    |    parent:      -1:000000000000
    |    user:        j.w.
    |    date:        Fri Mar 25 10:11:43 2011 -0700
    |    summary:     added bar in repo B
    |
    o  changeset:   0:bc6a6ad6a3e5
       user:        j.w
       date:        Fri Mar 25 10:11:15 2011 -0700
       summary:     added foo in repo A

One way you can do this is to pull from an unrelated repo, using hg pull -f.
This will result in a repository that has multiple roots.
You will still have the history from both repos, which will be represented by two lines of development in the repository.

The only trick here is to get the directory structure right. You want to root of your merged-in repos to match the root of your combined repo.

So for your case, I would imagine something like this:

    C:\> move SolutionFolder\Source\Project_A Temp_Project_A
    C:\> cd Temp_Project_A
    C:\Temp_Project_A> mkdir Source\Project_A
    C:\Temp_Project_A> hg rename * Source\Project_A
    C:\Temp_Project_A> hg ci -m "moved all Project_A files down in preparation for combining repos"
    C:\Temp_Project_A> cd ..\SolutionFolder
    C:\SolutionFolder> hg pull -f ..\Temp_Project_A
    C:\SolutionFolder> hg merge
    C:\SolutionFolder> hg ci -m "merged Project_A repo into main one"

    (and similar for Project B)

Check out the section beginning "It is possible to pull from completely unrelated repository..." in the Mercurial Wiki

Here is a generic example with real output:

    C:\>hg ini repoA

    C:\>hg ini repoB

    C:\>cd repoA

    C:\repoA>echo FOO > foo.txt

    C:\repoA>hg add
    adding foo.txt

    C:\repoA>hg ci -m "added foo in repo A"

    C:\repoA>cd ..\repoB

    C:\repoB>echo BAR > bar.txt

    C:\repoB>hg add
    adding bar.txt

    C:\repoB>hg ci -m "added bar in repo B"

    C:\repoB>cd ..

    C:\>hg clone repoA combinedRepo
    updating to branch default
    1 files updated, 0 files merged, 0 files removed, 0 files unresolved

    C:\>cd combinedRepo

    C:\combinedRepo>hg pull -f ..\repoB
    pulling from ..\repoB
    searching for changes
    warning: repository is unrelated
    adding changesets
    adding manifests
    adding file changes
    added 1 changesets with 1 changes to 1 files (+1 heads)
    (run 'hg heads' to see heads, 'hg merge' to merge)

    C:\combinedRepo>hg merge
    1 files updated, 0 files merged, 0 files removed, 0 files unresolved
    (branch merge, don't forget to commit)

    C:\combinedRepo>hg ci -m "merged repoB into repoA"

    C:\combinedRepo>hg gl
    @    changeset:   2:3d08641554c5
    |\   tag:         tip
    | |  parent:      0:bc6a6ad6a3e5
    | |  parent:      1:54dc5af30c7a
    | |  user:        j.w.
    | |  date:        Fri Mar 25 10:12:32 2011 -0700
    | |  summary:     merged repoB into repoA
    | |
    | o  changeset:   1:54dc5af30c7a
    |    parent:      -1:000000000000
    |    user:        j.w.
    |    date:        Fri Mar 25 10:11:43 2011 -0700
    |    summary:     added bar in repo B
    |
    o  changeset:   0:bc6a6ad6a3e5
       user:        j.w
       date:        Fri Mar 25 10:11:15 2011 -0700
       summary:     added foo in repo A
数理化全能战士 2024-11-01 22:12:57

如果您认为您有可能永远想要再次单独使用这两个存储库(即:在不同的解决方案中使用一个存储库,而不是另一个),那么您可以将它们作为新顶级的子存储库级别存储库。

为此,您只需 cd 进入 SolutionFolder 并创建一个名为 .hgsub 的文件,其中包含以下几行:

Source/Project_A = Source/Project_A
Source/Project_B = Source/Project_B

然后运行这些命令(仍在 SolutionFolder 中) >):

hg init
hg add .hgsub
hg commit -m 'new repo with two sub repos'

之后,您可以使用附加的 --subreposstatuscommit 等) code> 参数,它们将级联到子存储库中。

If you think there's a chance you'll ever want to use those two repositories separately again (i.e: use one in a different solution but not the other) then you can just make them subrepositories of a new top level repository.

To do that you'd just cd into SolutionFolder and create a file named .hgsub containing these lines:

Source/Project_A = Source/Project_A
Source/Project_B = Source/Project_B

then you run these commands (still in SolutionFolder):

hg init
hg add .hgsub
hg commit -m 'new repo with two sub repos'

After that you can do most all the normal Mercurial commands up in Solution Folder (status, commit, etc) with an additional --subrepos argument and they'll cascade down into the sub-repos.

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