Mercurial:如何与更改和更改的手动控制合并文件?

发布于 2024-08-24 22:18:26 字数 1487 浏览 5 评论 0原文

注意:我在这里描述的场景在Stack Overflow:完全手动 Mercurial 合并中没有得到解答。

我将用一个例子来解释我的查询。假设我启动 Mercurial 存储库来设计一辆汽车

C:\Car$ dir
Car.cpp
Car.h

我在汽车设计上工作了相当长一段时间,存储库看起来像:

r0-r1-...-r100-(default)

在某个时间点我分支默认 > 到 SolarCarBranch 并行处理太阳能汽车:

C:\SolarCar$ dir
Car.cpp
Car.h
Solar.cpp
Solar.h

再过一段时间,存储库看起来像:

r0-r1-...-r100-...-r200-(default)
            \--r101-...-r201-(SolarCarBranch)

How do I merge SolarCarBranch back to default?

请注意我想要的合并中的以下复杂情况:

  1. 合并后我应该能够继续处理 defaultSolarCarBranch
  2. SolarCarBranch 中的 Car.cppCar.h 中可能存在燃油效率修复,我希望将其纳入默认 ,但是我不希望这些文件中的所有更改。因此,我想在合并(也称为手动合并)期间挑选我想要包含在默认中的更改。
  3. 希望 Solar.cppSolar.h 出现在默认中。世界可能还没有准备好迎接太阳能汽车。 ;-)

我了解到:

  1. 这可以通过 hg merge SolarCarBranch 实现,
  2. 这可以通过在 Mercurial.ini 中设置 kdiff3.premerge=False 来实现code>
  3. 我不知道如何实现这一点,因为 premerge=False 仍然将 Solar.cppSolar.h 合并/复制到 默认,无需征求我的许可。

Note: The scenario I describe here is not answered in Stack Overflow: Completely manual Mercurial merge.

I will explain my query with an example. Assume I start off a Mercurial repository to design a car:

C:\Car$ dir
Car.cpp
Car.h

I work on the design of Car for quite a while and the repository looks like:

r0-r1-...-r100-(default)

At some point in time I branch default to SolarCarBranch to work on a solar powered car in parallel:

C:\SolarCar$ dir
Car.cpp
Car.h
Solar.cpp
Solar.h

After some more time, the repository looks like:

r0-r1-...-r100-...-r200-(default)
            \--r101-...-r201-(SolarCarBranch)

How do I merge SolarCarBranch back to default?

Take note of the following complications in the merge I want:

  1. I should be able to continue work on both default and SolarCarBranch after the merge.
  2. There might be fuel efficiency fixes in Car.cpp and Car.h in SolarCarBranch that I want pulled into default, however I do not want all the changes in those files. So, I want to cherry pick the changes I want to be included in default during the merge (aka manual merge).
  3. I do not want Solar.cpp and Solar.h appearing in default. The world may not yet be ready for a solar powered car. ;-)

What I have learned:

  1. This is possible by a hg merge SolarCarBranch
  2. This can be achieved by setting kdiff3.premerge=False in Mercurial.ini
  3. I do not know how to achieve this since premerge=False still merges/copies Solar.cpp and Solar.h into default without asking me for permission.

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

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

发布评论

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

评论(2

羞稚 2024-08-31 22:18:26

你真的很接近,你不需要求助于移植(恶心)或一般的樱桃采摘。关闭预合并是第一步,然后在合并之后、提交之前删除主分支中不需要的文件。您只需要做一次。

这是一个设置:

o  changeset:   3:343d531512a3
|  branch:      solar
|  tag:         tip
|  parent:      1:cb26642f8db5
|  user:        Ry4an Brase <[email protected]>
|  date:        Wed Mar 10 11:16:48 2010 -0600
|  files:       afile
|  description:
|  solar-change
|
|
| @  changeset:   2:c5d14e34db07
| |  parent:      0:56465175b2fc
| |  user:        Ry4an Brase <[email protected]>
| |  date:        Wed Mar 10 11:05:44 2010 -0600
| |  files:       other-main-file
| |  description:
| |  moremain
| |
| |
o |  changeset:   1:cb26642f8db5
|/   branch:      solar
|    user:        Ry4an Brase <[email protected]>
|    date:        Wed Mar 10 11:04:32 2010 -0600
|    files:       solar-only
|    description:
|    solar-initial
|
|
o  changeset:   0:56465175b2fc
   user:        Ry4an Brase <[email protected]>
   date:        Wed Mar 10 11:04:14 2010 -0600
   files:       afile
   description:
   initial

您可以看到变更集 1 将一个文件添加到 Solar 分支——默认情况下我们不需要这个文件。虽然变更集 3 调整了一个也存在于 main、afile 中的文件,但我们希望手动控制该更改是否发生。

hg update default 也是如此; hg merge -r Solar。合并工具将为afile弹出,如果我们想要这些更改,我们可以逐行或逐块决定。保存后执行 hg stat

% hg stat
M afile
M solar-only

我们看到 Solar-only 在默认情况下已排队等待提交。 只需删除它(使用if)。

% hg rm -f solar-only

现在,hg stat 将其显示为已删除:

% hg stat
M afile
R solar-only

当我们提交时,我们将在新的变更集中拥有我们想要的内容。

You're really close and you don't need to resort to Transplant (yuck) or cherry picking in general. Turning off premerge is the first step, and then just remove the files you don't want in the main branch after merging but before committing. You'll only have to do it once.

Here's a setup:

o  changeset:   3:343d531512a3
|  branch:      solar
|  tag:         tip
|  parent:      1:cb26642f8db5
|  user:        Ry4an Brase <[email protected]>
|  date:        Wed Mar 10 11:16:48 2010 -0600
|  files:       afile
|  description:
|  solar-change
|
|
| @  changeset:   2:c5d14e34db07
| |  parent:      0:56465175b2fc
| |  user:        Ry4an Brase <[email protected]>
| |  date:        Wed Mar 10 11:05:44 2010 -0600
| |  files:       other-main-file
| |  description:
| |  moremain
| |
| |
o |  changeset:   1:cb26642f8db5
|/   branch:      solar
|    user:        Ry4an Brase <[email protected]>
|    date:        Wed Mar 10 11:04:32 2010 -0600
|    files:       solar-only
|    description:
|    solar-initial
|
|
o  changeset:   0:56465175b2fc
   user:        Ry4an Brase <[email protected]>
   date:        Wed Mar 10 11:04:14 2010 -0600
   files:       afile
   description:
   initial

You can see that changeset 1 adds a file to the solar branch -- a file we don't want in default. While changeset 3 tweaks a file that also exists in main, afile, and we want to manually control whether or not that change happens.

So do hg update default ; hg merge -r solar. The merge tool will pop up for afile and we decide line-by-line or chunk-by-chunk if we want those changes. After saving do a hg stat:

% hg stat
M afile
M solar-only

And we see that solar-only is queued up for commiting in default. Just remove it (with if).

% hg rm -f solar-only

Now hg stat shows it as removed:

% hg stat
M afile
R solar-only

and when we commit we'll have what we want in the new changeset.

想挽留 2024-08-31 22:18:26

您的第一个条件是能够继续在两个分支上工作,只需不关闭分支即可满足(您可以使用 hg commit--close-branch 选项来完成此操作>)。

您可以使用 移植扩展 挑选要合并的变更集。这将允许您仅选择特定的变更集来合并到默认值中。

第三个条件满足的想法是,只要您不在同一提交中混合对普通汽车和太阳能汽车的更改,您就可以从太阳能分支拉回更改集而不受惩罚,而不必担心混合您的汽车类型。

您可能需要查看合并配置文档internal选项标志a>也是。

Your first condition, to be able to continue work on both branches, is satisfied by simply not closing the branch (which you do with the --close-branch option to hg commit).

You can cherry pick changesets to merge using the Transplant extension. This will let you choose only specific changesets to merge into default.

The third condition is satisfied by the the idea that provided you don't mix changes to both your regular car and your solar powered car in the same commit, you can pull changesets back from the solar branch with impunity, and not have to worry about mixing your car types.

You might want to look at the internal option flags in the merge configuration docs too.

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