如何使用 Mercurial 集成主要修订?

发布于 2024-10-30 08:44:57 字数 485 浏览 2 评论 0原文

首先,我对 Mercurial 和分布式源代码控制系统整体来说还是个新手。一般来说,我使用了 perforce,因此我将使用 perforce 术语,以便使我想说的内容清晰。

我的问题是,我正在制作一款基于开源引擎的游戏,并且该引擎会定期删除代码。然而,我也在我自己的仓库中亲自对引擎代码进行了一些更改。我需要进行一些设置,以便我可以轻松地将代码中的更改合并到我自己的代码中,而不会丢失我的更改,并且无需手动检查每个文件。

在 Perforce 中,我要做的就是为引擎代码创建一个分支,然后是我的主分支,所有引擎代码都将提交到引擎代码分支,然后我将引擎代码分支集成到主代码分支。解决问题,提交,瞧。

我觉得这与 Mercurial 中的工作方式非常接近,只是我缺少一些小的理解来帮助我弄清楚。首先,我不确定我的引擎代码是否应该位于分支中,或者完全独立的存储库中。即使我确实知道这一点,我也不清楚如何来回移动代码并使它们正确分开。

抱歉,如果这是厨房水槽问题。我倾向于通过把自己抛入深渊来学习。

First, I am new to Mercurial and distributed source control systems as a whole. Generally I have used perforce, so I'm going to use perforce terminology in order to keep what I'm trying to say clear.

My issue is that I'm making a game based on an open source engine, and that engine has regular code drops. However, I am also making some changes to the engine code myself, in my own depot. I need to set things up so that I can easily merge changes from code drops in to my own code, without losing my changes, and without having to examine every single file manually.

In Perforce, what I'd do is have a branch for just the engine code, and then my main branch, and all engine code drops would be submitted to the engine code branch, and then I would integrate the engine code branch in to the main code branch. Resolve problems, submit, and voila.

I feel like this is pretty close to how it would work in Mercurial, only I'm missing some minor piece of understanding to help me figure it out. First, I'm not sure if my engine code should be in a branch, or a completely separate repository. And even if I did know that, I'm not clear as to how I'd move code back and forth and keep them properly separate.

Sorry if this is kind of a kitchen sink question. I tend to learn by tossing myself in the deep end.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

海之角 2024-11-06 08:44:57

首先,我将引擎和游戏分开在两个存储库中。如果您想在其他地方使用修改后的引擎,如果您想为原始项目做出贡献,如果您想让某人参与引擎而不是游戏,...并将它们重新组合在一起,这会有所帮助,只需使用 subrepo 功能即可。

现在在游戏引擎修改领域,只要没有冲突的更改,您只需拉动合并,然后提交

让我们假设一个场景:

1----2----4----5---------8----A----B   <---- your changes
      \       /         /         /
       ---3-------6----7----9----/     <---- original changes

有一天您开始使用引擎 (1)。引擎已更新(2),但对您来说没问题,您可以像这样使用它。事实上不行,你必须改变一些东西(4),同时,改变是在原来的(3)上进行的。没问题,只需获取它们即可 (5) pull->merge->commit。哦,他们做了一个改变(6)和另一个改变(7)。好的,让我们将它们包括在内 (8) pull->merge->commit。依此类推,他们进行了更改 (9),您进行了更改 (A),然后合并了它们 (B)。

从集中式版本控制切换到分布式版本控制时需要记住的一件不自然的事情是,分支和合并是一个正常(且轻量级)的过程,而不是特殊的过程。有些人每天合并数百次。

为了更多的理解,尝试搜索“mercurial工作流程”(这里我公开了一个最小的工作流程)并阅读这本优秀的书Mercurial:布莱恩·奥沙利文 (Bryan O'Sullivan) 的《权威指南》

跟进评论

考虑一个像这样的最小项目:

mygame/
├── .hg/
├── .hgsub
├── lib/
│   └── engine/
│       ├── enginefile.cpp
│       └── .hg/
├── mygame.proj
└── src/
    └── mygamefile.cpp

现在您的评论:

另外,我希望能够工作
我的所有游戏内容都在同一个
存储库[...]

如果我理解得很好,事实上,您希望“能够在同一个[项目]中处理[您的]游戏的所有内容”。如果我做出了错误的猜测,请纠正我。

此处,包含 .hg 子目录的两个目录是单独的存储库(mygameengine)。但是您可以嵌套它们,而无需在 IDE 中创建单独的项目。所以有两个嵌套存储库,但只有一个项目。在您的构建配置(Makefile、解决方案等)中,您甚至可以将 mygame 引用到 engine 作为 engine 子存储库始终存在(通常使用游戏中引擎的标头)。

[...]是否可以得到它
稍微具体一点?例子
命令、存储库、路径等?

  • 对于路径,请查看第二张图。
  • 要更新引擎,请在 engine 目录 (cd lib/engine) 中:hg pullhg mergehg commit -m“将新的原始版本与我的修改合并”cd ..hg commit -m“更新到新的引擎版本”,现在您拥有了包含您的更改的新版本。
  • 对于其他基本用途,它看起来像其他版本控制系统。就您而言,这篇文章可能有助于将 perforce 映射到 Mercurial 命令。

First of all, I would separate the engine and the game in two repository. It helps if you want to use the modified engine elsewhere, if you want to contribute back to the original project, if you want to put someone on the engine but not on the game(s),... And to bring them back together, simply use the subrepo feature.

Now in the field of the game engine modifications, as long as there is no conflicting change, you simply have to pull, merge then commit.

Let's hypothesis a scenario:

1----2----4----5---------8----A----B   <---- your changes
      \       /         /         /
       ---3-------6----7----9----/     <---- original changes

One day you begin to use the engine (1). The engine is updated (2) but it is ok for you and you use it like that. In fact no, you have to change something (4), in the same time, changed are made on the original one (3). No problem, just fetch them (5) pull->merge->commit. Oh, they made a change (6) and another one (7). OK, let's include them (8) pull->merge->commit. And so on, they made changes (9), you make changes (A) and you merge them (B).

One unnatural thing to remember when switching from centralized to distributed version control is that branching and merging is a normal (and lightweight) process, not an exceptional one. Some people merge hundreds of time per day.

For more understanding try to search for "mercurial workflow" (here I exposed a minimal one) and read the excellent book Mercurial: The Definitive Guide by Bryan O'Sullivan

Follow up about comments

Consider a minimal project like this one:

mygame/
├── .hg/
├── .hgsub
├── lib/
│   └── engine/
│       ├── enginefile.cpp
│       └── .hg/
├── mygame.proj
└── src/
    └── mygamefile.cpp

And now your comments:

Also, I would like to be able to work
on all my game's content in the same
repository[...]

If I understand well, in fact, you want to "be able to work on all [your] game's content in the same [project]". Correct me if I made a false guess.

Here, the two directories containing a .hg subdirectory are separate repositories (mygame and engine). But you can nest them without making separated projects in your IDE. So two nested repositories, but only one project. In your build configuration (Makefiles, solutions, ...), you can even make references from mygame to engine as the engine sub-repository is always present (typically to use headers from the engine in your game).

[...] would it be possible to get it
slightly more specific? Example
commands, repositories, paths, etc?

  • For the paths, look at the second figure.
  • To update the engine, in the engine directory (cd lib/engine): hg pull, hg merge, hg commit -m "merge new original with my modifications", cd .., hg commit -m "updated to new engine version", now you have the new version with your changes included.
  • For other basic use, it looks like other version control system. In your case, this article could be useful to map perforce to mercurial commands.
夜司空 2024-11-06 08:44:57

听起来您可以在单个存储库中使用命名的 Mercurial 分支执行与 perforce 几乎完全相同的操作:

hg branch engine-code
hg ci -m "created engine code branch"
# add the engine code drop
hg ci -m "new drop"
hg update default
hg merge engine-code # merges engine-code drop into your default branch
# test the result of the merge, then commit it:
hg commit -m "merged new engine drop"

这是初始设置。之后,当你想添加一个新的掉落物时,它是类似的:

hg update engine-code
# add the new drop
hg ci -m "nother new drop"
hg update default
hg merge engine-code
hg ci -m "merged another new engine drop"

It sounds like you could do almost exactly the same thing you do with perforce using named mercurial branches in a single repository:

hg branch engine-code
hg ci -m "created engine code branch"
# add the engine code drop
hg ci -m "new drop"
hg update default
hg merge engine-code # merges engine-code drop into your default branch
# test the result of the merge, then commit it:
hg commit -m "merged new engine drop"

That's the initial setup. After that, when you want to add a new drop it's similar:

hg update engine-code
# add the new drop
hg ci -m "nother new drop"
hg update default
hg merge engine-code
hg ci -m "merged another new engine drop"
江心雾 2024-11-06 08:44:57

您想要的称为“供应商分支”——您可以在其中保存来自上游供应商的干净代码的分支。然后,您可以在另一个分支中进行自己的修改,并定期合并已放入供应商分支中的代码滴。非常像您在克鲁潘在回答中如何描述它的问题中自己描述的那样。

我编写了一组幻灯片来解释供应商分支如何在 Mercurial 中工作。凭借您的 Perforce 背景,您应该能够跟随他们。在 Mercurial 邮件列表中搜索“供应商分支”也显示了许多不错的命中

What you want is called a "vendor branch" -- a branch where you keep the clean code drops from your upstream vendor. You then make your own modifications in another branch and regularly merge in code drops that you have put into the vendor branch. Very much like you described it yourself in the question how krupan described it in his answer.

I have written a set of slides that explain how vendor branches work Mercurial. You should be able to follow them with your Perforce background. Searching the Mercurial mailinglist for "vendor branch" also shows many good hits.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文