简体   繁体   English

如何将一组mercurial存储库转换为git存储库?

[英]How do I convert a set of mercurial repositories into a git repository?

What I have 我有的

I currently have a set of mercurial repositories that contain source code. 我目前有一组包含源代码的mercurial存储库。 They use the “forked repository” scheme for branches. 他们使用分支的“分叉存储库”方案。 So, a feature “branch” might look like this: 因此,功能“分支”可能如下所示:

master repo           A→B→C
                    ———————↘—————
cool_feature repo           D→E→F

Once cool_feature is ready for prime time, we hg pull it into master so that it will look like this: 一旦cool_feature准备好黄金时间,我们hg pullhg pull入主机,这样它将如下所示:

master A→B→C→D→E→F

At that point, cool_feature will have the same stuff as master and it can be discarded. 那时, cool_feature将拥有与master相同的东西,它可以被丢弃。

Although D→E→F are in a separate repository at some points in time, they are always on the “default” branch in mercurial. 尽管D→E→F在某些时间点位于单独的存储库中,但它们始终位于mercurial中的“默认”分支上。 We do not use named branches to manage this data. 我们不使用命名分支来管理这些数据。

This works well in mercurial, but we're planning to move to git and git does things a little differently. 这在mercurial中效果很好,但是我们计划转向git并且git做的事情有点不同。 You can still fork repos in git, of course, but git branches are ephemeral and therefore usable for short-lived branches. 当然,你仍然可以在git中使用fork repos,但是git branch是短暂的,因此可用于短期分支。

What I want 我想要的是

I'd like to convert this to a single git repository that uses branches to manage work still in inventory. 我想将其转换为单个git存储库,该存储库使用分支来管理仍在库存中的工作。 In terms of process, we'll be using basically “git flow”. 在流程方面,我们将基本上使用“git flow”。 Pull requests will be between branches and once the work is complete, branches will be deleted. 拉取请求将在分支之间,一旦工作完成,分支将被删除。

master branch           A→B→C
                     ————————↘—————
cool_feature branch           D→E→F

What I've tried 我试过的

I can't simply use hg's convert , because it doesn't understand multiple repositories. 我不能简单地使用hg的convert ,因为它不了解多个存储库。 In fact, every tool in the entire hg-git ecosystem seems to want to convert git branches to hg branches and vice versa. 实际上,整个hg-git生态系统中的每个工具似乎都希望将git分支转换为hg分支,反之亦然。 (Despite evidence that suggests that the various communities use them very differently in practice.) (尽管有证据表明各社区在实践中使用它们的方式非常不同。)

One idea is to pull them into a single repository, convert it, then let git sort it out. 一个想法是将它们拉入单个存储库,转换它,然后让git对其进行排序。 After all, git only really needs to label the heads. 毕竟,git只需要标记头部。 The problem with this idea is most tools refuse to convert a multi-headed repository and if they do, git quietly discards the unlabeled heads as is its wont. 这个想法的问题是大多数工具拒绝转换多头存储库,如果他们这样做,git会悄悄地丢弃未经标记的头部。 If it's possible to label them after-the-fact, I haven't figured it out. 如果可以事后标记它们,我还没弄明白。

Another idea is to, within mercurial, move those changesets to a named branch and let the repository converter do the work. 另一个想法是,在mercurial中,将这些变更集移动到命名分支,并让存储库转换器完成工作。 This is tricky, because branches don't always start at a single spot: 这很棘手,因为分支并不总是从一个点开始:

master repo            A→B→C→F→G→H
                     ———————↘—————↘————————
nifty_feature repo           D→E   I→J
                                \    ↓
                                 +——→K→L→M (K is a merge of E and J)

This situation usually arises when two developers start work on a project together, but don't wind up with exactly the same changeset as their starting point. 当两个开发人员一起开始一个项目的工作时,通常会出现这种情况,但最终不会出现与他们的起点完全相同的变更集。 But there's no single point to select as the “upline” from which to create a branch. 但是没有一点可以选择作为创建分支的“上线”。

Another gnarly situation is when the first revision is a merge: 另一个可能的情况是第一次修订是合并时:

master repo          A→B———→C
                        \    \
                         +→D  \
                    ————————\——↘—————————
gnarly_feature repo          +—→E→F

Here, the “root” of the branch is E , a merge between C and D . 这里,分支的“根”是ECD之间的合并。 It's not immediately clear to me how you'd rebase that to a new branch, given that it is a merge revision. 鉴于它是一个合并修订版,我并不是很清楚你如何将它重新定义到一个新的分支。

For other reasons, I'm already running the conversion via reposurgeon, so I have access to some fairly fancy tools for modifying it in-flight. 由于其他原因,我已经通过reposurgeon运行转换,所以我可以访问一些相当奇特的工具来在飞行中修改它。 But every conversion takes ~20 hours, so trying a bunch of things that don't pan out has proven very expensive. 但是每次转换需要大约20个小时,所以尝试一堆没有成功的东西已经证明是非常昂贵的。

But it seems that since people do convert from hg to git and these are each commonly used branching schemes, somebody out there has surely solved this problem. 但似乎因为人们确实从hg转换为git并且这些都是常用的分支方案,所以有人在那里肯定解决了这个问题。 Any ideas for what tools to use or what strategies to try are welcome. 有关使用什么工具或尝试什么策略的任何想法都是受欢迎的。 How does one accomplish this? 如何实现这一目标?

they are always on the “default” branch in mercurial. 他们总是在mercurial的“默认”分支。 We do not use named branches to manage this data 我们不使用命名分支来管理这些数据

It's big error: you can use named branch+separate clone at the same time 这是一个很大的错误:您可以同时使用命名分支+单独的克隆

I'd like to convert this to a single git repository that uses branches to manage work still in inventory 我想将其转换为单个git存储库,该存储库使用分支来管理仍在库存中的工作

It can be big error 2 (in direction /from Hg to Git/ and methodology /single repo/) 它可能是大误差2(方向/从Hg到Git /和方法/单回购/)

every tool in the entire hg-git ecosystem seems to want to convert git branches to hg branches and vice versa. 整个hg-git生态系统中的每个工具似乎都希望将git分支转换为hg分支,反之亦然。

Just wrong. 错了。 I have Git-repo in hands, cloned with hg-git with a set of Git-branches . 我手里拿着Git-repo,用一组Git-branches克隆了hg-git。 On Mercurial's side I have (as expected) single branch 在Mercurial方面,我(如预期)有一个分支

>hg branches
default                     5266:1ffe854c93c1

and Git-branches, presented as hg-bookmarks (which they are really) 和Git-branches,作为hg书签呈现(他们真的是)

>hg book
   1.6                       2344:fc32e948fcba
   1.7                       5140:1c58e9bfa3d5
   2.0                       5219:683d072d02b6
   feature_dbpluginapi       4986:a855a635e17f
   feature_indexCleanup      5207:7ec7ee38ef2f
   feature_preview           4806:d40ade50b113
   feature_updateAll         4807:97ea12fea917
   master                    4620:de0053588acf

I can't simply use hg's convert, because it doesn't understand multiple repositories 我不能简单地使用hg的转换,因为它不了解多个存储库

But you have to use it for per-repository conversion: 但是您必须将它用于每个存储库转换:

  • Convert each feature-repo into intermediate Mercurial-repo, using --branchmap option (rename default branch into another... feature-name?) 使用--branchmap选项将每个feature-repo转换为中间Mercurial-repo(将default分支重命名为另一个... feature-name?)
  • Pull converted repo into master-repo; 将转换后的仓库转换为主仓库; you have to get full history, identical to old, with one exception: all feature-development will appear in unique named branches 您必须获得完整的历史记录,与旧的相同,但有一个例外:所有功能开发都将出现在唯一的命名分支中
  • Push aggregated repo to Git with hg-git or Git-Hg bridge 使用hg-git或Git-Hg桥将聚合回购推送到Git

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将git存储库转换为mercurial? - How do I convert a git repository to mercurial? 如何将带分支的Git存储库转换为可行的Mercurial存储库? - How can I convert a Git repository with branches to a workable Mercurial repository? 如何将我的Git存储库转换为Mercurial并带来其标签 - How do I convert my Git repository to Mercurial and bring along its tags 如何将 Mercurial 存储库转换为 Git(支持 LFS)? - How can I convert a Mercurial repository to Git (with LFS support)? 将Mercurial存储库转换为Git - Convert a Mercurial Repository to Git 如何使用hg-git关联现有的Mercurial和git存储库? - How do I relate an existing Mercurial and git repositories using hg-git? 如何在不丢失分支的情况下将mercurial存储库转换为git存储库? - How to convert mercurial repository to git repository without losing branches? 我怎么知道我的 git 存储库与我的 Mercurial 存储库相同? - How do I know my git repository is same as my Mercurial repository? 我如何设置 git clone 我的存储库之一 - How do I set up git clone one of my repositories 如何在将一个巨大的存储库拆分为单独的存储库的同时将 SVN 转换为 GIT? - How can I convert SVN to GIT while splitting one huge repository into separate repositories?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM