如何将现有的Mercurial存储库转换为使用子存储库并保持历史记录完整? [英] How to convert an existing Mercurial repository to use subrepositories and keep the history intact?

查看:88
本文介绍了如何将现有的Mercurial存储库转换为使用子存储库并保持历史记录完整?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读有关子存储库以及如何使用convert扩展名和文件映射将现有文件夹从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

我可以创建SubFolder的子存储库.我可以以几乎相同的方式将其他所有内容提取为单独的存储库(在本示例中,第二个存储库将仅具有root.txt文件).之后,我可以将SubFolder存储库作为子存储库添加到第二个存储库.但是,尽管两个存储库都有完整的历史记录,但是这些历史记录没有链接=>将根存储库更新为较早的状态不会使子存储库处于此时应处于的状态.仅当更新到已经知道子存储库并具有.hgsubstate文件的修订版时,才可以更新到一致的较旧版本(根目录和subrepo都自动更新).

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.

我想到的替代方法是,忘记当前存储库中SubFolder中的文件,并在SubFolder中初始化新存储库,同时添加.hgsub文件.从现在开始,我希望通过子存储库实现此工作,但是由于SubFolder的文件仍在当前存储库的历史记录中,因此仍然有一种方法可以更新到较旧的版本(在分离子存储库之前).

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.

但是这不起作用:当我忘记了文件时,创建了一个新的存储库并将其链接为当前存储库中的子存储库,并且在该子存储库存在之前我更新到了较旧的版本,我得到此错误: /p>

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'

这里的问题是,当更新到不知道该子存储库的较旧版本时,此更新程序希望将文件放入SubFolder中.但是此SubFolder仍然是另一个存储库(具有.hg目录),尽管主存储库没有相关记录,但该更新不希望将文件放入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.

是否总有办法解决此错误,或者有更好的方法切换到对现有Mercurial存储库中的某个文件夹使用子存储库并保持历史记录完整(并且两个历史记录都已链接)?

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)?

推荐答案

不,恐怕没有工具可以让您按照要求的方式拆分存储库.

Nope, I'm afraid there are no tools that will allow you to split a repository in the way you ask for.

只是为了澄清您的问题,然后让我们想象您有一个存储库,其中root.txtsub/file.txt的内容会像这样

Just to clarify your question, then let us imagine you have a repository where the content of root.txt and sub/file.txt evolve like this

   root.txt  sub/file.txt`
0: root 0    file 0
1: root 1    file 1
2: root 2    file 2

对于前三个变更集.您需要的是hg convert的选项,它将变成两个存储库(很容易,我们今天可以完成此操作),转换扩展将在其中注入.hgsub.hgsubstate文件,以便三个变更集包含

for 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 contain

   root.txt  .hgsub     .hgsubstate  |       file.txt
0: root 0    sub = sub  <X> sub      |  <X>: file 0
1: root 1    sub = sub  <Y> sub      |  <Y>: file 1
2: root 2    sub = sub  <Z> sub      |  <Z>: file 2

其中<X><Y><Z>哈希是与子存储库中的前三个提交相对应的哈希.

where the <X>, <Y>, and <Z> hashes are the one corresponding to the first three commits in the subrepository.

对于hg convert来说,今天没有这样的选项,但是根据以上所述,写一个是可行的.这将为您提供一种在组合存储库和拆分存储库之间来回转换的好方法.

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.

这篇关于如何将现有的Mercurial存储库转换为使用子存储库并保持历史记录完整?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆