问题描述
我有两个Mercurial存储库,分别用于同一项目的不同主要修订版.后一个版本是对项目功能(尤其是用户界面)的大量更改,但与早期版本相比,它仍然具有许多通用代码. (简而言之,我将这些版本称为4.6
和5.0
以及存储库 project-4.x 和 project-5.x );基本上就是这样我正在处理.)[1]
I have two Mercurial repositories that are for different major revisions of the same project. The latter version is a massive change to the functionality, and especially the UI, of the project, but it will still have a lot of common code with the earlier version. (For shorthand I'll call these versions 4.6
and 5.0
and the repositories project-4.x and project-5.x going forward; that's basically what I'm dealing with.)[1]
当我们更仔细地考虑存储库的结构,特别是考虑如何处理相关代码时,很明显,我们想简单地将存储库拉到一起,并使用命名分支来进行每个存储库中正在进行的工作(从哪些人可以根据需要分支或添加书签并合并).为此,我们决定基本上需要将 project-5.x 存储库放入 project-4.x 存储库.据我所知,合并存储库应该非常简单:
As we thought more carefully about the structure of our repository, and thinking especially about how to handle the related code, it became apparent that we wanted to simply pull the repositories together and used named branches for the ongoing work in each (from which people can branch or bookmark and merge as necessary). To do that, we decided we basically need to pull the project-5.x repository into the project-4.x repository. From what I can see, combining the repositories should be fairly straightforward:
$ hg pull -f project-5.x # in project-4.x
$ hg merge
到目前为止,太好了.我关心的是处理分支问题.[2]这些将作为两个完全不相关的链进入(很好),但是我希望分支结构看起来像这样:
So far, so good. My concern is handling the branching issue.[2] These are going to come in as two completely unrelated chains (which is fine), but I'd like the branch structure to look something like this:
---4.6----- }
\ } original project-4.x
5.0----- }
/
------- } original project-5.x
问题是,我不完全不确定如何做.
The problem is, I'm not exactly sure how to do it.
修改:请参见下文;我设计的答案奏效了.
See below; the answer I devised worked.
- 如果您想知道为什么现在才出现这种情况……好吧,该项目从
4.6
开始才得到版本控制.是的,这有点疯狂.而且我以前从未负责过像这样的主要版本更改,因此我最初决定完全制作一个新的存储库,我现在当然对此感到遗憾.生活和学习. - 我已经阅读了有关该主题的答案(但是我不确定如何准确地做到这一点):
- If you're wondering why this is only coming up now… well, the project only got version controlled as of starting
4.6
. Which, yes, is a little bit crazy. And I'd never been in charge of a major version change like this before, so I decided originally to make a new repo entirely, which I of course now regret. Live and learn. - Answers I've already read on the subject (but which left me unsure how to do this exactly):
- Mercurial - merging branches
- How do I merge two Mercurial repos into a single one
- How can I import a mercurial repo (including history) into another mercurial repo as a subdirectory, without using subrepos?
推荐答案
我本来以为我需要某种方式将其拉入分支,但是在仔细研究之后,我总结出最好的方法是大致如下:
I originally thought I'd need some way to pull into just the branch, but after chewing on it some more, I concluded the best way to do this is roughly as follows:
- 创建所需的新分支结构(即创建
4.6
和5.0
分支). - 将旧的
default
分支移至基础存储库中的4.6
分支. - 将 project-5.x 存储库拖入 project-4.x 存储库.
- 将在合并过程中引入的
default
(或在此存储库中为experimental
)基线合并到5.0
分支中,并沿该路径关闭experimental
分支. /li> - 限制对旧存储库的中央推/拉位置的写访问;我们出于历史原因仍然拥有它,但是人们不能不小心将其推入.
- Create the desired new branch structure (i.e. create the
4.6
and5.0
branches). - Remove the old
default
branch into the4.6
branch in the base repository. - Pull the project-5.x repository into the project-4.x repository.
- Merge the
default
(or in the case of this repository,experimental
) baseline, which is pulled in during the merge, into the5.0
branch, closing out theexperimental
branch along the way. - Restrict write access to the old repository's central push/pull location; we still have it for historical reasons, but people can't accidentally push to it.
准备(步骤1-2)
$ cd <project-4.x directory>
$ hg branch 4.6
$ hg ci -m "New 4.0 baseline"
$ hg branch 5.0
$ hg ci -m "New 5.0 baseline"
$ hg up default
$ hg ci --close-branch -m "Close default branch going forward.
$ hg up 4.6
$ hg merge default
$ hg ci -m "branch merge default -> 4.6"
此时,存储库已建立:它具有新的基准分支,并删除了我们想要摆脱的旧的default
分支.
At this point, the repository is set up: it has the new baseline branches and has removed the old default
branch we wanted to get rid of.
此后,我进行了更改,以使存储库结构看起来更像 project-4.x 存储库中5.0分支所需的方式(因为大规模重组是该版本的一部分)改变努力).
After this, I made the changes to get the repository structure looking more the way it needed to for the 5.0 branch in the project-4.x repository (since massive restructuring is part of the version change effort).
下一步实际上是将存储库合并在一起,然后将内容从旧存储库推送到所需的分支中.
The next step was actually merging the repositories together and pushing the content from the old repository into the desired branch.
$ hg pull -f <path to project-5.x repository> # still in project-4.x repository
$ hg merge -m "Merge in project-5.x repository"
$ hg up experimental # experimental is the name of the "default" branch
$ hg ci --close-branch -m "Close experimental branch"
$ hg up 5.0
$ hg merge experimental
$ hg ci -m "Merge old experimental into new 5.0 baseline"
这一切进行得很顺利,没有任何合并冲突(除了我需要解决我的.hgignore
文件中的一些小差异).
This proceeded perfectly, with no merge conflicts whatsoever (except that I needed to resolve some small differences in my .hgignore
file).
这篇关于Mercurial合并存储库作为分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!