将一些修订版与 Mercurial 合并,但不合并其他修订版

发布于 2024-11-02 18:26:35 字数 254 浏览 2 评论 0原文

我最近开始使用 Mercurial 跟踪我的项目的变化。在开始研究某个功能之前,我做了几次修改。现在,我想回到实现该功能之前的修订,并尝试以非常不同的方式实现它。但是,我想保留在第一个实现时所做的一些更改,因为无论我选择哪种实现,它们都同样适用。

在开始实现该功能之前,更新回修订版本的最佳方法是什么,但有选择地将默认分支上的更改合并到新的单独分支中?这是与 Mercurial 合并/分支的正确方法吗?如果我这样做,我以后可以“删除”其中一个分支以支持此功能的一个特定实现吗?

I recently started tracking changes for my project with Mercurial. I made several revisions before I started working on a certain feature. Now, I want to go back to my revision before I implemented that feature and try implementing it a very different way. However, I want to keep some of the changes I made while working on the first implementation because they apply equally no matter what implementation I choose.

What's the best way to update back to the revision before I started implementing the feature, but selectively incorporate changes along the default branch into a new, separate branch? Is this the right way to merge/branch with Mercurial? If I do this, can I later "drop" one of those branches in favor of one particular implementation of this feature?

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

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

发布评论

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

评论(2

寄与心 2024-11-09 18:26:35

如果您有像 Beyond Compare 这样的外部 diff 程序,这将非常容易。

  1. 启用 extdiff 扩展并将其配置为使用您的 diff 程序(例如,我有我的系统进行设置,以便 hg bcompare 将运行 Beyond Compare)将
  2. 存储库的工作目录更新为要在其中启动新分支的修订版本。
  3. 使用 Mercurial 对带有实验性更改的头部运行 diff 程序。
  4. 从实验代码中挑选您想要的更改,可以是整个文件,也可以是文件中较小的差异。
  5. 当您退出 diff 程序时,您的工作目录将包含您选择的更改。
  6. 启动一个新分支 (hgbranch) 或设置一个书签 (hg bookmark) 来跟踪这组新的更改。请参阅http://stevelosh.com/blog/ 2009/08/a-guide-to-branching-in-mercurial/ 了解差异的描述。
  7. 提交更改,然后就可以开始了!

当您决定想要哪种实现时,您可以更新到您不想要的分支的头部,并使用hg commit --close-branch将其标记为已关闭,这仍然将其作为存储库中的头部。如果您想将其作为头部删除,请更新为您想要的分支的头部并使用 hg merge --toolinternal:local合并它,但保留所有想要的更改。

This is very easy if you have an external diff program like Beyond Compare.

  1. Enable the extdiff extension and configure it to use your diff program (e.g. I have my system set up so that hg bcompare will run Beyond Compare)
  2. Update your repo's working directory to the revision where you want to start the new branch.
  3. Use Mercurial to run your diff program against the head with the experimental changes.
  4. Cherry pick the changes you want from the experimental code, either whole files or smaller diffs within files.
  5. When you exit your diff program, your working directory will have the changes you picked.
  6. Start a new branch (hg branch) or set a bookmark (hg bookmark) to track this new set of changes against. See http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/ for a description of the differences.
  7. Commit the changes, and off you go!

When you decide which implementation you want, you can either update to the head of the branch you don't want and use hg commit --close-branch to mark it as closed, which still leaves it as a head in the repository. If you want to remove it as a head, update to the head of the branch you do want and use hg merge --tool internal:local <rev-of-the-other-head> to merge it, but keep all the wanted changes.

若无相欠,怎会相见 2024-11-09 18:26:35

我知道这个问题有点老了,但我今天在做一个项目时遇到了类似的问题。我花了几天时间尝试默认分支上的一个功能。这是我用来使代码库恢复良好状态的过程。

  1. 我更新回了最后一个好的版本(在我的例子中,R0!)通过
    hg update -R 0
  2. 我为该功能创建了一个新分支(hg 分支 NEWFEATUREhg commit
  3. 我开始挑选好的东西
    通过 tranplant 从另一个分支提交(hg port -b
    默认 revNumberToPick)

移植现在随 Mercurial 一起发货,只需要您启用它。该文档位于 Mercurial wiki。希望这有帮助!

I know this question is a bit old, but I ran into something similar today when working on a project. I had spent a few days going down a dead-end trying out a feature on the default branch. Here's the process I used to get my code base back in a good condition.

  1. I updated back to the last good revision (in my case, R0!) via
    hg update -R 0
  2. I created a new branch for the feature (hg branch NEWFEATURE and hg commit)
  3. I started cherry-picking good
    commits from the other branch via tranplant (hg transplant -b
    default revNumberToPick
    )

Transplant is shipping in the box with mercurial now, and just requires you to enable it. The documentation is located on Mercurial wiki. Hope this helps!

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