在 Mercurial 中,如何从指定分支中选择特定文件以合并回默认分支?

发布于 2024-09-07 15:08:02 字数 223 浏览 1 评论 0原文

我有一个很大的命名分支,有很多变化。其中一些更改是非破坏性的,因此我想首先挑选出这些特定文件,并尽快将它们与默认文件合并。 (然后,破坏性更改也会被合并。)

在 Git 中,我将创建另一个分支并压缩索引外部的所有更改集,然后将特定文件添加到索引并提交。之后,我可以将这个临时分支与 master 合并,这样 master 就有了一个干净的提交,只有非破坏性的更改。我不知道如何使用 Mercurial 来做到这一点。

I have a big named branch with a lot of changes. Some of these changes are non-destructive so I want to pick these specific files out first, and merge them with default as soon as possible. (Then later, the destructive changes are merged as well.)

In Git I would create another branch and squash all changesets outside of the index, then I would add the specific files to the index and commit. After that, I could merge this temporary branch with master so master has a clean commit with only the non-destructive change. I don't know how to do this with Mercurial.

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

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

发布评论

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

评论(3

能否归途做我良人 2024-09-14 15:08:02

您可以使用 hg cat 获取任何特定分支上存在的文件内容,并用该文件替换工作副本版本。

从技术上讲,这不是合并,但由于您要替换整个文件,因此稍后合并内容时应该不会有太多麻烦:

例如,获取 myfile.c 表单分支 somefeature,并替换工作副本版本,请执行以下操作:

hg cat path/to/myfile.c -r somefeature > path/to/myfile.c

请注意这完全替换了工作副本文件,因此首先确保您没有任何未完成的更改

You can use hg cat to grab the contents of a file as it exists on any particular branch, and replace the working copy version with that.

This isn't technically a merge, but since you're replacing whole files you shouldn't have too much of a bad time merging things later:

for example, to grab myfile.c form branch somefeature, and replace the working copy version, do:

hg cat path/to/myfile.c -r somefeature > path/to/myfile.c

note that this completely replaces the working copy file so make sure you have no outstanding changes first

桃扇骨 2024-09-14 15:08:02

我认为 mercurialqueues 就是你想要的。使用 mq 您可以将任何变更集转换为补丁和变更集中的任何补丁。因此,采用一个变更集将其转换为补丁,从补丁中删除您不需要的块,然后将其应用到您想要的任何分支。这是一个相当复杂操作需要你有一定的纪律。因此,在您关心的代码上尝试之前,我会尝试在测试存储库上确定您的工作流程。

I think mercurialqueues is what you want. With mq you can turn any changeset into a patch and any patch into a changeset. So taking a changeset converting it to a patch deleting the chunks out of the patch that you don't want and then applying it to whatever branch you want. This is a fairly complex operation though and requires a certain amount of discipline on your part. So I would try to nail down your workflow on a test repo before trying it on code you care about.

猫七 2024-09-14 15:08:02

据我所知,Mercurial 没有任何工具来分割变更集。如果幸运的话,您想要的所有更改都位于单独的更改集中,然后您可以使用 TransplantExtension。我认为它可以与 Git 的cherry-pick 相比较,但我并没有太多使用 git。

您还可以使用 hg diff 手动将对某个文件的更改提交到新分支。使用转速范围来标记整个源分支:

hg diff myfile -r startrevision:endrevision

输出可以视为补丁。对您想要的每个文件执行此操作并提交它们,然后合并。跳过破坏性的变化。当然,您也可以在修订范围的中间多次进行破坏性更改。

话虽如此,你想做的事情并不是 Mercurial 的初衷。核心历史编辑更多的是 Git 的领域(请注意,这只是我的观点)。将稳定的更改和破坏性的更改保留在单独的变更集中(甚至可能在单独的分支中)。我使用 移植rebasestrip< /a> 移动更改。全部完成后,它们将被合并并正确推送。

哦,检查 MercurialQueues。我自己没有使用过它,但我见过它做了一些疯狂的事情。也许它能够按照您想要的方式做一些事情。

As far as I know, Mercurial doesnt any have tools to split changesets. If youre lucky, all the changes you want are in separate changesets and then you can use the TransplantExtension. I think it can be compared to Git's cherry-pick but I havent used git much.

You can also use hg diff to manually commit the changes to a certain file to a new branch. Use the rev range to mark your entire source branch:

hg diff myfile -r startrevision:endrevision

The output can be treated as a patch. Do this for each file you want and commit them and then merge. Skipping the destructive changes. You can also, of course, do this multiple times of a destructive change is in the middle of a revision range.

Having said that what youre trying to do isnt something mercurial was built for. That hardcore history editing is more Git's area (note that its just my opinion). Keep your stable changes and destructive changes in separate changesets (and maybe even in separate branches). I use transplant, rebase and strip to move changes around. When its all done, they are merged and properly pushed.

Oh, and check MercurialQueues. I havent used it myself but Ive seen it do some crazy stuff. Maybe its capable of doing something along the lines of what you want.

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