HG:匹配远程存储库的变更集
我正从 Git 迁移到 HG,并且在 HG 对我施加的一些限制方面遇到了困难:
我面临的情况是,我有一些错误的提交,我想消除它们。事实上,如果我能够匹配远程存储库的历史记录,那就太好了。
使用 git,这非常简单:
git reset --hard origin/branch_name
但是如何使用 Mercurial 做到这一点呢?据我所知,如果您不知道自己在做什么,则移动“尖端”可能会无意中产生匿名分支,这与 git 处理相同操作的方式非常不同。
I'm moving to HG from Git and having a hard time with some of the restrictions HG is imposing on me:
I am in a situation where I have some erroneous commits that I want to blow away. In fact, It would be really nice if I could just match the remote repo's history.
With git, this was easy as pie:
git reset --hard origin/branch_name
But how can I do it with Mercurial? From what I've heard, moving the 'tip' around can inadvertently spawn off anonymous branches if you don't know what you are doing, which is very different from how git handles the same operation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一个经常被忽视的简单解决方案是简单地克隆它们来消除不需要的提交:
现在
new_clone
让您回到远程存储库的提示。如果您的克隆中还有尚未推送但仍需要的其他提交,您可以在本地克隆:现在
new_clone
包含您提交之前的所有内容想要的,但排除那些你想扔掉的。在这种情况下,您只需在new_clone
的 hgrc 中设置[paths]
以指向原始源存储库,然后您就可以回到开始的位置。这很简单,不需要扩展,但请注意,manojlds 建议使用 hg strip 会更快,并且您可以保留可能需要的任何未跟踪文件。无论哪种情况,只有在您尚未推送想要删除的变更集的情况下,这才有效。如果您已经推送,唯一安全的选择是
hg backout
。A simple solution that's often overlooked for blowing away unwanted commits is to simply clone them away:
Now
new_clone
puts you back at the remote repo's tip. If you've got other commits in your clone that you haven't pushed yet, but still want, you can clone locally:Now
new_clone
contains everything up to the commits you wanted, but excludes the ones you wanted to trash. In this case, you simply need to setup[paths]
innew_clone
's hgrc to point to the original origin repo and you're back to where you started.This is easy and requires no extensions, but note that manojlds's suggestion of using
hg strip
will be faster, and you get to keep any untracked files you might have needed. In either case, this will only work assuming you have not yet pushed the changesets you want to blow away. If you've already pushed, your only safe option ishg backout
.您想要的“等效”是 MQ 扩展中的
hg strip
,您可以使用它来“吹走”您的提交。https://www.mercurial-scm.org/wiki/StripExtension
另一个“等效项” “ 是:
http://www.selenic.com/mercurial/hg.1.html#更新
"Equivalent" for what you want is
hg strip
from MQ extension, which you can use to "blow away" your commits.https://www.mercurial-scm.org/wiki/StripExtension
Another "equivalent" is:
http://www.selenic.com/mercurial/hg.1.html#update
Git 用户的 Mercurial 有一个命令等效表:
Mercurial for Git users has a command equivalence table:
使用 Mercurial 1.8 及更高版本,您可以启用标准条扩展并执行
此操作,这将使用 revset 选择要剥离的修订版本,即默认远程存储库中尚未存在的额外修订版本。
With Mercurial 1.8 and later you can enable the standard strip extension and do
This will use a revset to select the revisions to strip, namely the extra revisions not yet present in the default remote repository.