如何在 Hg 中同时处理默认分支和分支?

发布于 2024-11-05 07:23:26 字数 558 浏览 1 评论 0原文

好吧,我对 Mercurial 和版本控制分支总体来说是个新手,所以我可能对这里发生的事情有一个根本性的误解——请友善......;)

我们是一个小型开发团队(2 名开发人员),致力于项目,我们需要实施一项相当重大的改变,这可能需要数周或数月的时间。同时,该程序处于日常使用中,因此我们需要定期进行补丁和修复。

由于重大更改的长期运行性质,我在默认分支之外创建了一个分支(称为 dev1)。我希望定期将默认分支中的更改合并到 dev1 分支中,其原因无需在此重申。但是,我不希望将 dev1 中的更改合并到默认分支中,直到开发的后期。

我尝试了几种不同的方法来做到这一点,但合并似乎总是影响两个分支。合并后,如果我更新到默认值,我现在会将 dev1 中的更改合并到源中。

我可以使用同一个存储库在两个分支上工作吗?如果是这样,有人可以分享要使用的命令序列吗?如果没有,在我看来,在完成之前我将无法将 dev1 分支推送到主存储库,而这似乎不对。

我们正在运行最新的 Windows 版 TortoiseHg,而且我最喜欢这个图形工具。但是,我非常愿意在必要时使用命令行来执行某些任务。

感谢您的帮助, 戴夫

OK, I'm new to Mercurial and version control branching in general, so I may have a fundamental misunderstanding of what's going on here -- please be kind... ;)

We are a small development team (2 developers) working on a project, and we have a need to implement a fairly significant change that may take weeks or months. At the same time, the program is in daily use, so we have a need to make regular patches and fixes.

Because of the long-running nature of the significant change, I created a branch off the default branch (call it dev1). I will want to periodically merge the changes from the default branch into the dev1 branch, for reasons that don't need to be reiterated here. However, I do NOT want the changes from dev1 merged into the default branch until much later in the development.

I have tried several different ways to do this, but it always seems the merge affects both branches. After the merge, if I update to the default I now have changes from dev1 merged into the source.

Can I work on both branches using the same repository? If so, can someone please share the sequence of commands to use? If not, it seems to me I would not be able to push the dev1 branch up to the master repo until it was finished, and that just doesn't seem right.

We are running the latest TortoiseHg for Windows, and for the most part I love the graphical tool. However, I am perfectly willing to drop to the command line to do certain tasks when necessary.

Thanks for any help,
Dave

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

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

发布评论

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

评论(5

-小熊_ 2024-11-12 07:23:27

这取决于您创建的分支类型。

如果您创建了一个命名分支,并且在单个工作目录中工作,那么您需要使用一个工作流程,但如果您克隆了生产存储库,则需要使用不同的工作流程。

命名分支工作流程,单个存储库/工作目录

在本例中,您使用 update 在 default 分支和 dev1 功能分支之间切换。

当您想要在 default 分支上工作时,请更新它,修复错误,然后提交这些更改。不要合并来自 dev1 分支的更改。

当您想要在 dev1 分支上工作时,请更新它,合并默认分支中的错误修复,处理您的功能并在完成后提交。

如果您正在 dev1 分支上工作,并且同事修复了您需要的 default 中的错误,请提交您的工作,获取其更改,合并它们,然后继续您的工作(您可以在此处使用快捷方式,但这样如果合并变得混乱,您可以取消合并)

注意:所有这些都假设您的所有更改都在您想要在 dev1default 分支。

需要注意的重要一点是,当您合并时,您只能从 default 中的 dev1 分支获得更改。如果您只合并 defaultdev1 中,那么您的功能分支将与 default 保持同步,这样当您准备好将该功能部署到 default 分支时,您可以通过一个简单的合并操作来做到这一点。

使用从生产存储库克隆的 dev1 存储库的未命名分支工作流程

此工作流程类似,但允许您同时处理 defaultdev1 分支,而无需必须更新才能在两者之间切换。

当您想要在 default 分支上工作时,请使用提示是您的生产代码的存储库。像平常一样修复错误并提交这些更改。

当您想要在 dev1 分支上工作时,请使用尖端是您的 dev1 功能分支的存储库。如果 default 存储库中有修复,请提取更改并将其合并到您的克隆中,但不要将合并更改集推回。仅当您想要将功能部署到生产代码时才推送变更集。合并 default 中的变更集后,您可以继续处理该功能。

如果您正在 dev1 分支上工作,并且同事修复了您需要的 default 中的错误,请提交您的工作,将他们的更改从您的共享存储库提取到您的 default 生产克隆,然后将这些更改拉入您的 dev1 功能克隆,将它们合并,然后继续您的工作。

再次强调,需要注意的重要一点是,当您将更改推送到 default 生产环境时,您只能从 default 中的 dev1 分支获取更改存储库。如果您仅将 default 变更集拉取/合并到 dev1 克隆中,那么您的功能分支将与 default 保持同步,以便您准备好时要将功能部署到 default 分支中,您可以通过一个简单的推送操作来完成。

This depends on what sort of branch you've created.

If you have created a named branch, and are working in a single working directory, then you need to use one workflow, but if you have cloned your production repository, you need to use a different workflow.

Named branch workflow, single repo/working directory

In this case, you are using update to switch between the default branch and the dev1 feature branch.

When you want to work on the default branch, update to it, do your bug fixes, and commit those changes. Do not merge in changes from dev1 branch.

When you want to work on your dev1 branch, update to it, merge in your bug fixes from the default branch, work on your feature and commit when done.

If you are working on the dev1 branch and a colleague fixes a bug in default that you need, commit your work, fetch their changes, merge them in and then resume your work (there are shortcuts you can take here, but this way you can backout the merge if it gets messy)

Note: All of these assume that all of your changes are committed at the point you want to switch between dev1 and default branches.

The important thing to note is that you only get the changes from your dev1 branch in default when you merge them in. If you only merge default into dev1 then your feature branch will keep up to date with default so that when you are ready to deploy the feature into the default branch, you can do so with one simple merge operation.

Unnamed branch workflow using dev1 repo cloned from production repo

This workflow is similar, but allows you to work on the default and dev1 branches simultaneously, without having to update to switch between the two.

When you want to work on the default branch, use the repository where the tip is your production code. Do your bug fixes, and commit those changes just as you would normally.

When you want to work on your dev1 branch, use the repository where the tip is your dev1 feature branch. If there have been fixes in the default repository, pull in the changes and merge them into your clone, but do not push the merge changeset back. Only push your changeset back when you want to deploy you feature to production code. Once the changesets from default have been merged in, you can continue working on the feature.

If you are working on the dev1 branch and a colleague fixes a bug in default that you need, commit your work, fetch their changes from your shared repository into your default production clone, then pull those changes down into your dev1 feature clone, merge them in and then resume your work.

Again, the important thing to note is that you only get the changes from your dev1 branch in default when you push them up to your default production repository. If you only pull/merge default changesets into the dev1 clone then your feature branch will keep up to date with default so that when you are ready to deploy the feature into the default branch, you can do so with one simple push operation.

葬﹪忆之殇 2024-11-12 07:23:27

是的,您绝对可以使用 Mercurial 做到这一点。

首先,如果您不清楚(我有一段时间也不清楚),有 Mercurial 中的 3 种类型的“分支”

  • 克隆存储库
  • “命名分支”(使用 hgbranch 命令)
  • 匿名分支,您可以使用书签进行管理或仅记住变更集

我猜您使用了 hgbranch 方法。请注意,这通常不是您想要的,因为该分支名称将永远存在于存储库的历史记录中(嗯,有 --close-branch 选项,但是仍然...)。

基本工作流程是:

  • 使用 hg up devbranch 更新到 dev 分支
  • 将更改提交到 dev 分支
  • 通过 hg merge default 或仅 hg merge 与主分支合并> 根据需要
  • (根据需要重复)

对于在默认分支上工作:

  • 使用 hg up default 更新到默认分支
  • 提交更改
  • (根据需要重复)

不要这样做:

  • 使用 更新到默认分支>hg 默认值
  • 使用 hg merge 与 dev 分支合并

我怀疑您在使用命令 hg merge 时未指定分支名称。它将与任何其他头部合并,这可能是也可能不是您想要的。

编辑:以上信息可能不是您的问题。您的问题可能是在当前分支是默认分支时运行合并。

不想从默认分支运行hg merge

Yes, you can absolutely do this with Mercurial.

First, in case it isn't clear to you (it wasn't to me for some time), there are 3 types of 'branches' in Mercurial:

  • clone a repository
  • a 'named branch' (using the hg branch command)
  • an anonymous branch, which you can manage with bookmarks or just remembering the changeset

I'm guessing that you used the hg branch method. Be aware that this is often not what you want, because that branch name will live in the repo's history forever (well, there is the --close-branch option, but still...).

The essential workflow is:

  • update to dev branch with hg up devbranch
  • commit changes to dev branch
  • merge with main branch via hg merge default or just hg merge as desired
  • (repeat as desired)

And for working on the default branch:

  • update to default branch with hg up default
  • commit changes
  • (repeat as desired)

Do NOT do this:

  • update to default branch with hg up default
  • merge with dev branch with hg merge

I suspect that you are using the command hg merge without specifying a branch name. That will merge with any other head, which may or may not be what you want.

Edit: The above info is probably not your issue. Your issue is probably running a merge when your current branch is the default one.

You don't want to run hg merge from your default branch.

|煩躁 2024-11-12 07:23:27
# bang on dev1
# more banging on dev1
# someone beats on default for a while
# update to dev1
hg up dev1
# bring in the changes from default
hg merge -r default
# validate successful merge
hg commit -m "merging"

关键是当您从默认值进行更改时在 dev1 上提交。

请注意,我在这里使用命名分支。

# bang on dev1
# more banging on dev1
# someone beats on default for a while
# update to dev1
hg up dev1
# bring in the changes from default
hg merge -r default
# validate successful merge
hg commit -m "merging"

The key is committing on dev1 when you bring changes over from default.

Note that I'm using named branches here.

策马西风 2024-11-12 07:23:27

这句话:

合并后,如果我更新到默认值,我现在会将 dev1 的更改合并到源中。

告诉我你做错了什么。您想要做的事情是完全可行的,并行地在两个分支上工作,并从一个分支合并到另一个分支,而不影响两者。

重要的是要知道合并是定向合并。您将一个分支合并到另一个分支,当您启动合并时,您应该 -分支。

方向是指方向在结果中发挥作用。对于文件的实际内容,合并的方向并不重要,但是您提交的新合并变更集将位于您启动合并时所在的分支上(除非您覆盖)。

因此,更新到首先是 dev1 的 head,然后与 default 合并,提交后,您应该在 dev1 分支上有一个新的变更集,但是 default 应该保持不变。

This sentence:

After the merge, if I update to the default I now have changes from dev1 merged into the source.

tells me that you're doing something wrong. It is perfectly doable what you want to do, work on two branches in parallel, and merge from one to the other, without influencing both.

It is important to know that the merge is a directional merge. You merge from one branch to the other, and when you initiate the merge, you should be on the to-branch.

directional in the sense that the direction plays a role in the outcome. For the actual contents of the file, it doesn't matter which direction you merge, but the new merge-changeset you commit will be on the branch you was on when you initiated the merge (unless you override.)

So, update to the head of dev1 first, then merge with default, and after committing, you should have a new changeset on the dev1 branch, but default should be left undisturbed.

极度宠爱 2024-11-12 07:23:27

这更多的是一个提示而不是一个答案,但是......

我经常使用这个工作流程。我发现 Transplant 扩展对于命名分支工作流程非常有用。 TortoiseHg 支持它,因此您可以在 TortoiseHg 选项中启用它。它可以让你从其他分支中挑选,这非常有用 - 特别是如果你经常提交到错误的分支。

This is more of a tip than an answer, but...

I use this workflow a lot. I find the Transplant extension very useful for named branch workflows. TortoiseHg supports it, so you can enable it in the TortoiseHg options. It lets you cherry-pick from other branches, which is very useful - especially if you regularly commit to the wrong branch.

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