如何使用两个并行的主要分支来重组Mercurial存储库 [英] How to restructure a mercurial repository with two main, parallel branches

查看:66
本文介绍了如何使用两个并行的主要分支来重组Mercurial存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的存储库的历史记录如下:

The history of my repository looks like:

A -- B -- C (branch "foo")
      \
       -- D (branch "bar")

这两个分支都是运输"分支,并且对于公共后端本质上是不同的前端.

The two branches are both "shipping" branches, and are essentially different frontends to a common backend.

所有代码以前都在一个分支中,通过编译器开关打开或关闭foobar功能,但是我进行了分支以简化分别使用每个代码的过程.

All the code used to be in one branch, with the foo or bar features turned on or off by a compiler switch, but I branched to make it easier to work with each individually.

问题在于普通的后端"文件本身可能应该是一个单独的分支-我经常想只是在那些普通文件上工作.由于我创建这些分支的方式,历史有些混乱:在分支bar的过去,它曾经具有foo的功能.

The problem is that the common "backend" files, by themselves, probably should be a separate branch - and I often want to just work on those common files. Because of the way I created these branches, the history is a bit screwed up: in branch bar's past, it used to have features from foo.

当前,我只是简单地在一个分支上进行更改,然后使用hg transplant将相同的更改复制到另一分支上.

Currently, I simply make changes on one branch and then use hg transplant to copy the same changes to the other branch.

相反,我希望能够通过以下方式进行更改:

Instead, I'd like to be able to make changes this way:

       __ C __ D'   (branch "foo")
      /      /
A -- B -- D         (branch "backend")
      \      \
       -- E -- D''  (branch "bar")

也就是说,在分支backend上工作,然后在每个发货分支(foobar)中,我使用hg merge backend.

That is, work on the branch backend, and then in each of the shipping branches (foo and bar), I use hg merge backend.

从目前的状况转到我要描述的最佳方式是什么?我能想到的唯一方法是:

What's the best way to go from my current situation to the one I'm describing? The only way I can think of is:

  1. 删除所有foobar功能,并命名分支backend.

  1. Remove all foo and bar features, and name that branch backend.

删除旧的foobar分支.

手动将foo功能添加到backend并命名分支foo,并为bar命名.

Manually add foo features to backend and name that branch foo, and likewise for bar.

有更好的方法吗?

这也是正确的做法吗?

推荐答案

我选择将其拆分为多个存储库,而不是一个存储库中的多个分支,如下所示:

I chose to split it into multiple repositories instead of several branches in one repository, as follows:

  1. 我关闭了bar分支.

我将原始存储库克隆到了新的存储库backend.

I cloned the original repository into a new repository backend.

我删除了所有与foo相关的代码.

I removed all of the foo-related code.

我将这些更改拉到主存储库中,然后立即撤消了这些更改(因此仍保留了foo代码).这成为了我的foo存储库.

I pulled those changes into the main repository, and then immediately backed out of them (so the foo code remains). This became my foo repository.

我将backend存储库克隆到了新的存储库bar.

I cloned the backend repository into a new repository bar.

我将所有文件从现在关闭的bar分支复制并粘贴到了bar存储库中.

I copied-and-pasted all of the files from the now-closed bar branch into the bar repository.

这将我的历史记录保存为foo,并丢失了bar记录的连续性(尽管如果需要,所有历史记录仍然存在);现在foobar都是backend存储库的克隆(经过修改),这正是我想要的.

This kept my history for foo, and lost the history's continuity for bar (although all the history is still there, if I needed it); and now both foo and bar are clones, with modifications, of the backend repository, which is exactly what I wanted.

这篇关于如何使用两个并行的主要分支来重组Mercurial存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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