Mercurial 克隆清理以匹配上游

发布于 2024-12-06 22:25:12 字数 536 浏览 0 评论 0原文

我有一个存储库的 hg 克隆,在几个月内我在其中进行了许多本地更改,并将它们推送到我在 google code 的克隆中。不幸的是,作为一个菜鸟,我在默认分支上提交了一大堆更改。

现在我想确保我当前的默认值与上游完全一样,然后我可以对默认值进行适当的分支并仅在分支上工作。

但是我该如何进行清理呢?

作为参考,我的克隆是 http://code.google.com/r/mosabua -roboguice/source/browse

PS:我在使用 git 时遇到了同样的问题,并解决了这个问题:清理 git master 分支并将一些提交移动到新分支?

I have a hg clone of a repository into which I have done numerous changes locally over a few months and pushed them to my clone at google code. Unfortunately as a noob I committed a whole bunch of changes on the default branch.

Now I would like to make sure my current default is EXACTLY as upstream and then I can do proper branching off default and only working on the branches..

However how do I do that cleanup though?

For reference my clone is http://code.google.com/r/mosabua-roboguice/source/browse

PS: I got my self into the same problem with git and got that cleaned up: Cleanup git master branch and move some commit to new branch?

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

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

发布评论

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

评论(4

一瞬间的火花 2024-12-13 22:25:12

首先,在默认分支上提交没有任何问题。您通常不希望为 Mercurial 中的每个任务创建单独的命名分支,因为命名分支是永久的。您可能想查看书签功能以获取更接近 git 分支的功能(“hg 帮助书签”)。因此,如果现有变更集唯一的问题是它们位于默认分支上,那么它们确实没有任何问题。别担心。

然而,如果你真的想重新开始,最明显、最直接的事情就是从上游重新克隆。您可以通过移动现有存储库并重新克隆来保留混乱的变更集。然后将旧存储库中的变更集移植到您选择的分支上的新存储库中。

如果您不想花费时间/带宽来进行新克隆,可以使用(高级、危险、不适合初学者)strip 命令。首先,您必须启用 mq 扩展(通过 google 搜索或查看手册 - 我故意不在这里解释它,因为它很危险)。然后运行

hg strip 'outgoing("http://upstream/path/to/repo")'

注意,我正在使用 Mercurial 1.7 中添加的 revsets 功能。如果您使用的是旧版本,则没有简单的方法可以做到这一点。

First, there's nothing wrong with committing on the default branch. You generally don't want to create a separate named branch for every task in Mercurial, because named branches are forever. You might want to look at the bookmark feature for something closer to git branches ("hg help bookmarks"). So if the only thing wrong with your existing changesets is that they are on the default branch, then there really is nothing wrong with them. Don't worry about it.

However, if you really want to start afresh, the obvious, straightforward thing to do is reclone from upstream. You can keep your messy changesets by moving the existing repo and recloning. Then transplant the changesets from the old repo into the new one on a branch of your choosing.

If you don't want to spend the time/bandwidth for a new clone, you can use the (advanced, dangerous, not for beginners) strip command. First, you have to enable the mq extension (google it or see the manual -- I'm deliberately not explaining it here because it's dangerous). Then run

hg strip 'outgoing("http://upstream/path/to/repo")'

Note that I'm using the revsets feature added in Mercurial 1.7 here. If you're using an older version, there's no easy way to do this.

音栖息无 2024-12-13 22:25:12

最好的方法是使用两个克隆。当使用远程存储库时,我无法控制,我总是保留一个名为“virgin”的本地克隆,我不对其进行任何更改。例如:

hg clone -U https://code.google.com/r/mosabua-roboguice-clean/ mosabua-roboguice-clean-virgin
hg clone mosabua-roboguice-clean-virgin mosabua-roboguice-clean-working

请注意,因为 Mercurial 对本地克隆使用硬链接,并且因为第一个克隆是带有 -U 的克隆(没有工作目录(git 术语中的裸存储库)),所以这占用了 no 额外的磁盘空间。

在 robo-guice 工作中进行所有你想要的工作,并拉入 robo-guice 处女来查看上游发生了什么,然后再次拉入 roboguice-working 以获取上游更改。

您可以在事后通过创建远程存储库的新克隆来执行类似的操作,如果磁盘空间宝贵,请使用重新链接扩展来关联它们。

The best way to do this is with two clones. When working with a remote repo I don't control I always keep a local clone called 'virgin' to which I make no changes. For example:

hg clone -U https://code.google.com/r/mosabua-roboguice-clean/ mosabua-roboguice-clean-virgin
hg clone mosabua-roboguice-clean-virgin mosabua-roboguice-clean-working

Note that because Mercurial uses hard links for local clones and because that first clone was a clone with -U (no working directory (bare repo in git terms)) this takes up no additional disk space.

Work all you want in robo-guice working and pull in robo-guice virgin to see what's going on upstream, and pull again in roboguice-working to get upstream changes.

You can do something like this after the fact by creating a new clone of the remote repo and if diskspace is precious use the relink extension to associate them.

回忆躺在深渊里 2024-12-13 22:25:12

前言 - 所有历史更改仅对未发布的存储库有意义。编辑本地历史记录后,您必须从头开始推送到 GoogleCode 的存储库(在 GC 上删除存储库、创建空存储库、推送) - 否则您将在默认分支

Manfred

Easy(但不短)方式中再获得一个 HEAD - 仅默认+MQ

  1. 正如 Greg 提到的,安装 MQ
  2. 将所有提交移动到上游代码顶部的 MQ 补丁中,
  3. 将更改保留为路径,永远
  4. 检查,如果需要则进行编辑,并在每次上游拉取后重新集成补丁(这样您自己的没有 MQ 补丁的 CG-repo 将变得与上游相同)

更复杂 - 中间的 MQ + 上面的单独分支

  1. 创建
  2. 命名
  3. 分支,切换到它
  4. “完成”补丁
  5. 拉动上游,与您的分支更改合并(默认 yourbranch)
  6. 仅将更改提交到yourbranch

变基

  1. 启用变基扩展
  2. 创建命名分支(其中包含变更集?待定)
  3. 将您的变更集变基到新的祖先,测试结果
  4. 请参阅5-6 来自“更复杂”章节

Preface - all history changes have sense only for non-published repos. You'll have to push to GoogleCode's repo from scratch after editing local history (delete repo on GC, create empty, push) - otherwise you'll gust get one more HEAD in default branch

Manfred

Easy (but not short) way - default only+MQ

  1. as Greg mentioned, install MQ
  2. move all your commits into MQ-patches on top of upstream code
  3. leave your changes as pathes forever
  4. check, edit if nesessary and re-integrate patches after each upstream pull (this way your own CG-repo without MQ-patches will become identical to upstream)

More complex - MQ in the middle + separate branches

  1. above
  2. above
  3. create named branch, switch to it
  4. "Finish" patches
  5. Pull upstream, merge with your branch changes (from defaut to yourbranch)
  6. Commit your changes only into yourbranch

Rebasing

  1. Enable rebase extension
  2. Create named branch (with changeset in it? TBT)
  3. Rebase your changesets to the new ancestor, test results
  4. See 5-6 from "More complex" chapter
我做我的改变 2024-12-13 22:25:12

也许您可以尝试转换扩展。它可以使存储库处于更好的状态,同时保留历史。当然,修改完成后,您必须删除旧的存储库并上传转换后的存储库。

Perhaps you could try the Convert extension. It can bring a repository in a better shape, while preserving history. Of course, after the modifications have been done, you will have to delete the old repo and upload the converted one.

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