HG:匹配远程存储库的变更集

发布于 2024-12-02 11:33:16 字数 284 浏览 0 评论 0原文

我正从 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 技术交流群。

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

发布评论

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

评论(4

十雾 2024-12-09 11:33:16

一个经常被忽视的简单解决方案是简单地克隆它们来消除不需要的提交:

hg clone origin new_clone
rm -rf repo_with_unwanted_commits

现在 new_clone 让您回到远程存储库的提示。如果您的克隆中还有尚未推送但仍需要的其他提交,您可以在本地克隆:

hg clone -r tip_you_want repo_with_unwanted_commits new_clone
rm -rf repo_with_unwanted_commits

现在 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:

hg clone origin new_clone
rm -rf repo_with_unwanted_commits

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:

hg clone -r tip_you_want repo_with_unwanted_commits new_clone
rm -rf repo_with_unwanted_commits

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] in new_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 is hg backout.

大海や 2024-12-09 11:33:16

您想要的“等效”是 MQ 扩展中的 hg strip,您可以使用它来“吹走”您的提交。

https://www.mercurial-scm.org/wiki/StripExtension

另一个“等效项” “ 是:

hg update --clean

使用 -C/--clean 选项,未提交的更改将被丢弃,并且
工作目录已更新为请求的变更集。

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:

hg update --clean

With the -C/--clean option, uncommitted changes are discarded and the
working directory is updated to the requested changeset.

http://www.selenic.com/mercurial/hg.1.html#update

月下伊人醉 2024-12-09 11:33:16

Git 用户的 Mercurial 有一个命令等效表:

git reset --hard == hg revert -a --no-backup

Mercurial for Git users has a command equivalence table:

git reset --hard == hg revert -a --no-backup

晨光如昨 2024-12-09 11:33:16

使用 Mercurial 1.8 及更高版本,您可以启用标准条扩展并执行

hg strip "outgoing()"

此操作,这将使用 revset 选择要剥离的修订版本,即默认远程存储库中尚未存在的额外修订版本。

With Mercurial 1.8 and later you can enable the standard strip extension and do

hg strip "outgoing()"

This will use a revset to select the revisions to strip, namely the extra revisions not yet present in the default remote repository.

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