Mercurial 克隆清理以匹配上游
我有一个存储库的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先,在默认分支上提交没有任何问题。您通常不希望为 Mercurial 中的每个任务创建单独的命名分支,因为命名分支是永久的。您可能想查看书签功能以获取更接近 git 分支的功能(“hg 帮助书签”)。因此,如果现有变更集唯一的问题是它们位于默认分支上,那么它们确实没有任何问题。别担心。
然而,如果你真的想重新开始,最明显、最直接的事情就是从上游重新克隆。您可以通过移动现有存储库并重新克隆来保留混乱的变更集。然后将旧存储库中的变更集移植到您选择的分支上的新存储库中。
如果您不想花费时间/带宽来进行新克隆,可以使用(高级、危险、不适合初学者)
strip
命令。首先,您必须启用mq
扩展(通过 google 搜索或查看手册 - 我故意不在这里解释它,因为它很危险)。然后运行注意,我正在使用 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 themq
extension (google it or see the manual -- I'm deliberately not explaining it here because it's dangerous). Then runNote 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.
最好的方法是使用两个克隆。当使用远程存储库时,我无法控制,我总是保留一个名为“virgin”的本地克隆,我不对其进行任何更改。例如:
请注意,因为 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:
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.
前言 - 所有历史更改仅对未发布的存储库有意义。编辑本地历史记录后,您必须从头开始推送到 GoogleCode 的存储库(在 GC 上删除存储库、创建空存储库、推送) - 否则您将在默认分支
Manfred
Easy(但不短)方式中再获得一个 HEAD - 仅默认+MQ
更复杂 - 中间的 MQ + 上面的单独分支
变基
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
More complex - MQ in the middle + separate branches
Rebasing
也许您可以尝试转换扩展。它可以使存储库处于更好的状态,同时保留历史。当然,修改完成后,您必须删除旧的存储库并上传转换后的存储库。
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.