Hg:将许多存储库加入到一个存储库中

时间:2014-09-26 20:02:15

标签: maven mercurial

我使用mercurial来管理我的资源。 今天我有12个不同的存储库,每个存储库大约有6个分支。 每个存储库都包含一个maven项目。 我想创建一个父项目并将我的所有项目声明为模块,并将所有项目合并到一个存储库中。 为了视觉,今天我有: -Repo1 / PROJECT1 -Repo2 /项目2 ... -Repo12 / project12

我想: - globalRepo with      - module1      - module2      - ......      - module12

保留分支机构和历史(如果可能)。

这样做的最佳做法是什么? (Subrepo,合并......)

Thx!

2 个答案:

答案 0 :(得分:1)

可以将不相关的存储库拉到一起并合并它们。诀窍是在进行合并之前将文件重命名为特定目录。

例如,以下脚本创建三个单独的存储库,每个项目的根目录中包含三个文件。然后,它将它们组合到一个存储库中,每个项目中的文件都移动到子目录:

@REM Create three separate repositories
hg init Repo1
hg init Repo2
hg init Repo3
@REM Add and commit files to each of them.
cd Repo1
echo >file1
echo >file2
echo >file3
hg ci -Am r1
cd ..\Repo2
echo >file4
echo >file5
echo >file6
hg ci -Am r2
cd ..\Repo3
echo >file7
echo >file8
echo >file9
hg ci -Am r3
cd ..
@REM Create a global repo.
hg init globalRepo
cd globalRepo
@REM Pull in the first repo and move the files in it to a module1 subdirectory.
@REM Force the pull since it is an unrelated repo and update to it.
hg pull ..\Repo1 -f
hg update tip
md module1
hg rename * module1
hg ci -m "Rename Repo1 files to module1 directory."
@REM Pull in the second repo and move the files in it to a module2 subdirectory.
hg pull ..\Repo2 -f
hg update tip
md module2
hg rename * module2
hg ci -m "Rename Repo2 files to module2 directory."
@REM Merge the two unrelated branches together.
hg merge
hg ci -m "Merge the two unrelated repositories together."
@REM Pull in the third repo, rename, and merge.
hg pull ..\Repo3 -f
hg update tip
md module3
hg ren * module3
hg ci -m "Rename Repo3 files to module3 directory."
hg merge
hg ci -m Merge

结果如下所示。请注意,原始三个项目的整个历史记录都将以没有父节点的根节点开头。文件被移动到每个项目的最终目录目的地,然后合并在一起。

TortoiseHg graph of the final result

答案 1 :(得分:1)

这是我的复杂性顺序列表,从最简单的开始。

忘记历史

最简单的。将每个项目的默认分支的当前状态放在新项目结构中。然后开始一个新的回购。

我们还没有被告知分支机构有多活跃,但如果它们处于活动状态,您可以为每个分支执行相同的操作:

hg up null       # not strictly necessary, but may avoid the impression that a branch started now.
hg branch <name>
<populate directory structure with the current state of a branch from each project>
hg commit

您仍然可以访问原始项目回购中的历史记录。您无法轻易做到的是将新的变更集与旧历史进行比较。显然,对此的需求随着时间的推移而减少,但对你来说可能很重要。

<强>合并

通过合并回购可以保留历史。首先,每个项目仓库必须将其所有文件移动到子目录以反映全局仓库的预期结构:

for <each project>
    md projdir
    hg rename * projdir
    hg commit

然后每个项目都可以进入全球项目:

cd globalrepo
hg init
hg pull <first subproject>
for <other subprojects>
    hg pull -f <subproject>     # the -f is necessary because the projects are unrelated.
    hg merge
    hg commit

这应该会让你合并完整的历史。

在比较具有“旧”历史记录的文件时,请记住(或使用别名)对具有--git选项(至少是diff和export)的命令使用--git选项。请记住,虽然历史可能已经完成,但可能会令人困惑,因为每个项目的历史都是连续的。

使用子目录

可以使用您建议的行使用子版本来加入回购。话虽如此,subrepos旨在不太活跃独立组件。在您的用例中,这些都不是真的。

在您的情况下,项目将不是独立的,因为它们仅用于新的全局仓库的上下文中,而不与其他全局仓库共享。

如果subrepos处于活动状态,就像在用例中那样,你必须保持警惕,记住提交subrepo和父repo。不记得这会导致刺激,因为多头会导致推动中断。如果A人将变更集推送到subrepo而不推送父repo,则会发生这种情况;然后人B更新到父回购的尖端(它没有拉新的subrepo变更集),并尝试在同一子程序上推送他的提交。如果你团队中的每个人都对Hg有资格,那么对你来说可能没什么问题,但如果没有,我建议你不要使用subrepos作为你的用例。

如果有活动分支,子目录将保留它们,但是除非它也是分支的,否则全局仓库将不会看到它们:

cd globalrepo
hg up null       # not strictly necessary, but may avoid the impression that a branch started now.
hg branch <branch>
for <each subrepo>
    cd <project dir>
    hg up <branch>
cd globalrepo
hg commit

我希望你能得到这个想法(未经测试,这一点来自记忆)。

相关问题