使用 Mercurial Hg 时的替代方案

发布于 2024-11-30 11:04:16 字数 723 浏览 0 评论 0原文

我想征求您的意见,了解在使用 Mercurial 时我应该使用以下哪些例程,或者哪些例程更可取。假设我有最新的代码。
第一个例程如下:

  1. 完成我的工作
  2. hg commit
  3. 如果需要,重复步骤 1 和 2
  4. 当我准备好推送时,我 hg pullhg update
  5. hg merge, hg commit
  6. hg Push

第二个是:

  1. 做我的工作
  2. 当我准备好提交时 hg pull,<代码>hg更新
  3. hg commit, hg Push

事实是,据我所知,第一个替代方案是大多数开发人员(应该)使用的方案,因为与第二个选项不同在使用方面,它提供了使用本地存储库的机会,因为这对于 DVCS 来说是很正常的事情。

我的同事鼓励我使用第二种方式,因为这样我可以避免分支和后来可能出现的合并问题(因为在过去,不知何故,他们有这样的问题),所以我留在主干开发线上。 我想第一个选项应该是更可取的选项,因为与 CVCS 不同,在 DVCS 中合并是不应该害怕的,并且它给了我使用本地存储库的机会。

I would like to get your opinion on which of the following routines should I use, or which of them is more desirable, when using Mercurial. Suppose that I have the latest code.
First routine is following:

  1. Do my work
  2. hg commit
  3. Repeat steps 1 and 2 if needed
  4. When I'm ready to push I hg pull, hg update
  5. hg merge, hg commit
  6. hg push

Second is:

  1. Do my work
  2. when I'm ready to commit I hg pull, hg update
  3. hg commit, hg push

The thing is that, as far as I know the first alternative is the one which most of the developers (should) use because, unlike in second option of usage, it provides the opportunity to use local repository, as it is a normal thing for DVCS.

My colleagues encourage me to use the second way, because that way I avoid branching and later possible problems with merging (because in past, somehow, they had such problems), so I stay on trunk development line.
I guess that the first option is the option that should be preferable because merging is something that shouldn't be afraid of in DVCS, unlike in CVCS, and it gives me the opportunity of using local repository.

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

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

发布评论

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

评论(2

守不住的情 2024-12-07 11:04:16

在这两种情况下,您要做的工作没有任何区别:

  • 对于第一个工作流程,您将在步骤 5 中进行合并。

  • 使用第二个工作流程,您将执行与步骤 2 中更新的一部分完全相同的合并。

使用第二个工作流程,您将执行与步骤 对于许多人来说,工作流程感觉更安全,因为您正在处理已经提交的工作。这意味着如果合并变得复杂,那么返回到干净状态是微不足道的:hg update -C .

但即使使用第二个工作流程,您实际上也可以取回原始文件:hg resolve --all --tool internal:local 将重做 hg update 开始的合并并选择所有文件的原始版本。

真正的区别在于第一个工作流程更好地显示了实际发生的情况。通过该工作流程,您可以通过更小、更合乎逻辑的步骤来呈现您的更改。当你的大学试图了解你做了什么(代码审查)和未来的调试(使用 hg bisect)时,这会很有帮助。

通过 hg rebase,您可以两全其美。这让你可以做出小的、合乎逻辑的承诺,然后最终将这些承诺转移到你的大学所做的工作之上。在这种情况下,不会有合并变更集——美好而丰富的线性历史。

因此,如果您在拉取后有此历史记录:

... [a] --- [b] --- [x] --- [y] --- [z]
               \
                [d] --- [e]

您在其中创建了 xz,那么正常的合并将创建此历史记录:

... [a] --- [b] --- [x] --- [y] --- [z]
               \                       \
                [d] --- [e] ----------- [f]

通过变基,您将获得

... [a] --- [b] --- [d] --- [e] --- [x'] --- [y'] --- [z']

x'z'xz 的重新基版本(不同的变更集 ID,因为它们具有不同的祖先)。

我一直这样使用 rebase,我觉得它提供了最好的整体历史记录。请记住不要对已经公开的变更集进行变基:变基会修改变更集,但如果变更集已经是公开的,那么您就很难修改其他副本。结果是重复的变更集和混乱。

There is not any difference in the work you will be doing in both cases:

  • with the first workflow, you will do a merge in step 5.

  • with the second workflow, you do the exact same merge as part of the update in step 2.

The first workflow feels safer to many since you're working on already committed work. This means that it's trivial to get back to a clean state if the merge turns out to be complicated: hg update -C ..

But you can actually get your original files back even with the second workflow: hg resolve --all --tool internal:local will redo the merge that hg update started and select the original version for all files.

The real difference is that the first workflow better shows what actually happened. With that workflow you can present your change in smaller and more logical steps. That helps a lot when your colleges try to understand what you did (code reviews) and with future debugging (with hg bisect).

You can get the best of both world with hg rebase. That lets you make small and logical commits and then finally move those commits on top of the work done by your colleges. There wont be a merge changeset in that case -- nice and rich linear history.

So if you have this history after the pull:

... [a] --- [b] --- [x] --- [y] --- [z]
               \
                [d] --- [e]

where you have created x to z, then a normal merge would create this history:

... [a] --- [b] --- [x] --- [y] --- [z]
               \                       \
                [d] --- [e] ----------- [f]

With a rebase you get

... [a] --- [b] --- [d] --- [e] --- [x'] --- [y'] --- [z']

where x' to z' are the rebased versions of x to z (different changeset IDs because they have different ancestors).

I use rebase like this all the time and I feel it gives the best overall history. Just remember not to rebase changesets that have already been made public: rebasing modifies the changesets, but if the changesets are already public, then it's difficult for you to modify the other copies. The result is duplicate changesets and confusion.

漆黑的白昼 2024-12-07 11:04:16

基本上,您自己已经回答了这个问题:

第一个例程是 DVCS 的“默认”例程,因为它利用了典型的 DVCS 功能
(本地存储库,由于不涉及网络而更快的提交,由于许多小提交与少数大提交而导致更详细的历史记录......)

使用第二个例程并不是“错误”或“不好”,但您必须意识到事实上,您使用 DVCS 的方式就像使用 CVCS 一样,因此您有意选择不使用 DVCS 的一些优点(见上文)。

长期 CVCS 用户(可能像您的同事)通常更喜欢第二种例程,因为这感觉更像他们已经知道的东西。
另外,合并在 DVCS 中比 CVCS 效果更好,因此他们的“合并可能出现问题”的论点可能只是因为他们过去在 CVCS 中遇到过问题,并假设在 DVCS 中也是一样的(这是事实并非如此)。

Basically, you already answered the question yourself:

The first routine is the "default" one for DVCS because it takes advantage of the typical DVCS features
(local repository, faster commits because no network is involved, more detailed history because of many small commits vs. few big ones...)

Using the second routine is not "wrong" or "bad", but you have to be aware of the fact that you're using a DVCS as if it were a CVCS, so you intentionally choose not to use some of the advantages of a DVCS (see above).

People who are long-time CVCS users (like your colleagues, probably) often prefer the second routine because that feels more what they already know.
Plus, merging works better in DVCS than CVCS, so their "possible problems with merging" argument is probably only because they had problems in CVCS in the past and assume it will be the same in DVCS (which is not the case).

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