如何将现有的 Mercurial 存储库转换为使用子存储库并保持历史记录完整?
我一直在阅读有关子存储库以及如何使用转换扩展和文件映射将现有文件夹从 Mercurial 存储库提取到子存储库的内容。我可以成功地做到这一点。如果我有以下文件夹结构:
C:\Project
---Project\root.txt
---Project\SubFolder
---Project\SubFolder\fileinsubfolder.txt
我可以创建 SubFolder 的子存储库。以大致相同的方式,我可以将其他所有内容提取到单独的存储库中(在本例中,第二个存储库只有 root.txt 文件)。之后,我可以将 SubFolder 存储库作为子存储库添加到第二个存储库。但是,尽管两个存储库都有完整的历史记录,但这些历史记录并没有链接=>将根存储库更新到较早的状态不会使子存储库处于当时应有的状态。仅当更新到已了解子存储库并具有 .hgsubstate 文件的修订版时,更新到一致的旧版本(根和子存储库均自动更新)才有效。
我想到的替代方案就是忘记当前存储库中 SubFolder 中的文件,并在 SubFolder 中初始化一个新存储库,同时添加 .hgsub 文件。我希望在这里实现的是从此时开始使用子存储库,但仍然有办法更新到旧版本(在分离子存储库之前),因为 SubFolder 的文件仍然在当前存储库的历史记录中。
但这不起作用:当我忘记了 Mercurial 中的文件,启动了一个新的存储库并将其链接为当前存储库中的子存储库,并且在子存储库存在之前更新到旧版本时,我收到此错误:
C:\Project>hg update 1
abort: path 'SubFolder\fileinsubfolder.txt' is inside repo 'SubFolder'
这里的问题是当更新到不知道子存储库的旧版本时,此更新希望将文件放入子文件夹中。但这个 SubFolder 仍然是另一个存储库(有一个 .hg 目录),尽管主存储库没有关于它的记忆,但更新不想将文件放入 SubFolder,因为它是一个存储库。
是否有办法解决此错误,或者是否有更好的方法可以切换到对现有 Mercurial 存储库中的某个文件夹使用子存储库并保持历史记录完整(并且两个历史记录都链接)?
I've been reading about subrepositories and how to extract an existing folder from a Mercurial repository to a subrepository using the convert extension and a filemap. I can successfully do this. If I have the following folder structure:
C:\Project
---Project\root.txt
---Project\SubFolder
---Project\SubFolder\fileinsubfolder.txt
I can make a subrepository of SubFolder. In much the same way I can extract everything else a seperate repositorie (in this example the second repository would just have the root.txt file). Afterwards I can add the SubFolder repository as a subrepository to the second repository. But although both repositories have the complete history, these histories aren't linked => updating the root repository to an earlier state won't put the subrepository in the state it should be at that point. Updating to a consistent older revision (both root and subrepo updated automatically) will only work when updating to a revision that already knows about the subrepository and has .hgsubstate file.
And alternative I thought about was just forgetting the files in SubFolder in the current repository and initing a new repository in SubFolder and at the same time add a .hgsub file. What I hope to achieve here is work from this point on with a subrepository but still have a way to update to an older revision (before separating the subrepo) because the files of SubFolder are still in the history of the current repository.
This doesn't work though: When I have forgotten the files in mercurial, inited a new repo and linked it as a subrepo in the current repo and I update to an older revision before the subrepo existed I get this error:
C:\Project>hg update 1
abort: path 'SubFolder\fileinsubfolder.txt' is inside repo 'SubFolder'
The problem here is that when updating to an older revision which wasn't aware of the subrepo, this update wants to put files in the SubFolder. But this SubFolder is still another repo (has a .hg directory) and although the main repo has no recollection about it, the update doesn't want to put files in the SubFolder as it is a repo.
Is there anyway to get around this error or is there a better method to switch to using a subrepo for a certain folder in an existing Mercurial repository and keep the history intact (and both histories linked)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,恐怕没有任何工具可以让您按照您要求的方式拆分存储库。
为了澄清您的问题,然后让我们假设您有一个存储库,其中
root.txt
和sub/file.txt
的内容对于前三个变更集是这样演变的。您要求的是
hg Convert
的一个选项,它将把它变成两个存储库(很简单,我们今天就可以做到),并且转换扩展会注入.hgsub
和 < code>.hgsubstate 文件,以便三个变更集包含
、
和目前,
hg Convert
还没有这样的选项,但基于上面的内容,编写一个听起来是可行的。这将为您提供一种在组合存储库和拆分存储库之间来回转换的好方法。Nope, I'm afraid there are no tools that will allow you to split a repository in the way you ask for.
Just to clarify your question, then let us imagine you have a repository where the content of
root.txt
andsub/file.txt
evolve like thisfor the first three changesets. What you ask for is an option for
hg convert
that would turn this into two repositories (easy, we can do that today) and where the convert extension injects.hgsub
and.hgsubstate
files so that the three changesets containwhere the
<X>
,<Y>
, and<Z>
hashes are the one corresponding to the first three commits in the subrepository.There is no such option for
hg convert
today, but based on the above it sounds feasible to write one. That would give you a great way to convert back and forth between a combined and a split repository.