简体   繁体   English

从特定版本中提取文件 - mercurial

[英]pull files from a specific revision - mercurial

I have 3 repositories, each created with the same code base but different enough to warrant different repositories. 我有3个存储库,每个存储库都使用相同的代码库创建,但又足以保证不同的存储库。 My "dream" work flow would be to do work in the development repository and then pull these changes into the other repositories. 我的“梦想”工作流程是在开发存储库中完成工作,然后将这些更改提取到其他存储库中。 I know I can do this with something like: 我知道我可以这样做:

hg pull -r X -f repo

but this will give me all changesets up to X. Is it possible to just pull all the changesets from a specific revision or even from a range of revisions? 但这会给我所有的变更集到X.是否可以从特定版本甚至从一系列修订中提取所有变更集?

There is no good way to cherry pick revisions in mercurial (that's what your proposed workflow is called). 在mercurial中没有很好的方法来挑选修订(这就是你提议的工作流程)。 There are some not-so-great ways to do it: export+import (or the convenience wrapper around export+import called transplant), but the draw back there is you have the same changeset with different hashes in multiple repositories, with no good way to represent that if/when you try to move changes across again. 有一些不那么好的方法可以做到:export + import(或者导出+导入的方便包装器称为移植),但是那里的缺点是你有多个存储库中不同哈希的相同变更集,没有好处表示当您尝试再次移动更改时的方式。

Better is to modify your workflow so that when you want to move over a change you're okay with moving over all of its ancestors, and you do this by consciously picking a changeset's ancestors. 更好的是修改你的工作流程,这样当你想要移动一个变化时,你可以移动它的所有祖先,并且你通过有意识地选择变更集的祖先来做到这一点。

For example, if you're fixing a bug that's in the development repository, and all three "other" repositories don't just change the change's parent revision the tip of the development repository. 例如,如果您正在修复开发存储库中的错误,并且所有三个“其他”存储库不仅仅将更改的父修订版更改为开发存储库的tip First do a hg update -r THE_REVISION_WHERE_THE_BUG_WAS_ADDED , then fix your bug, and then commit. 首先做一个hg update -r THE_REVISION_WHERE_THE_BUG_WAS_ADDED ,然后修复你的bug,然后提交。 You'll see a message saying new head created , which is expected. 您将看到一条消息,说明new head created ,这是预期的。

Now you'd got that fix as a changesets whose only parent is the changeset in which the bug was introduced -- which must exist in the 3 other repositories or they wouldn't have the bug. 现在你已经将修复程序作为一个变更集,其中唯一的父项是引入错误的变更集 - 必须存在于其他3个存储库中,否则它们不会有错误。 So now you can pull that new changeset into the "3" other repositories without bringing everything else in development with them. 因此,现在您可以pull新的变更集转移到“3”其他存储库中,而无需将其他所有变更集合到其中。 And then you do a quick hg merge in each of those four repositories blending the bug fix into their deployable tip . 然后你在这四个存储库中的每一个中快速进行hg merge ,将错误修复混合到他们的可部署tip

Getting a handle of how to structure repositories with common functionality but customizations in each, can be a little tricky, but if you structure things right you can do all of your intra-repo migrations using using push, pull, and merge, and never have to fix a bug twice, have the same code in different changesets, or re-do a repository's customization. 了解如何使用通用功能构建存储库但在每个存储库中进行自定义的处理可能有点棘手,但如果您正确构建,则可以使用推送,拉取和合并来执行所有的内部仓库迁移,并且永远不会修复错误两次,在不同的更改集中使用相同的代码,或者重新执行存储库的自定义。

As a note, the bisect command, does a great job of answering the "where was this bug introduced" question before one starts fixing it. 作为一个注释,bisect命令在开始修复它之前,很好地回答了“这个bug引入的地方”的问题。

Updated answer: From Mercurial 2 onwards, you can use the ' graft ' command that works nicely. 更新的答案:从Mercurial 2开始,您可以使用可以很好地运行的' graft '命令。 It uses some internal merging capabilities to make sure you can handle any conflicts manually. 它使用一些内部合并功能来确保您可以手动处理任何冲突。 If there are no conflicts that Mercurial can't resolve itself, the new changeset is automagically cherrypicked and committed on top of your current revision. 如果没有Mercurial无法自行解决的冲突,那么新的变更集将在您当前的修订版本之上自动执行。

如果您想获取某些更改集的内容并将其应用于任意签出(请注意:生成的更改集将是不同的更改集 ,即使它们进行相同的更改 ),请查看transplant扩展

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM