Mercurial如何回滚到某个标签?
我对如何回滚到 Mercurial 中的标签有点困惑。 (我对此很陌生)
假设我有一个名为“Version-1.0”的标签,这是几次修订前的。假设我们现在处于 r400
现在,如果我的经理告诉我他们不喜欢事情的发展方向,并且基本上想放弃该标签以来的所有内容并返回到版本 1.0。
好吧,我可以通过以下方式检查该标签:
hg update -r 版本-1.0
好的,现在我回到了版本 1.0 标签,如果我永远不需要进行更改,那就没问题了。然而,一旦我做出更改并提交,我现在就有了 2 个头(我对 Version-1.0 和 r400 的新更改是经理想要放弃的东西)。
所以现在我需要与r400合并。我不想。 (我真的不想把所有这些变化从地球上抹去,我希望它们保留在我的历史中,这样如果管理层再次改变主意,我可以稍后再回到它们)但我目前不想要其中任何一个。
我该怎么办?
更新
答案指出:
您可以克隆整个存储库直到标签,然后使用该克隆作为您的“新”中央存储库。
如果我的中央存储库由 bitbucket 托管,我不知道该怎么做。如果当前邮件位于 URL https://[电子邮件受保护]/jisaacks/hgml
并且我想将其克隆到标记到名为 hgml2
的新存储库(尚不存在)我在我的计算机上本地尝试了此命令:
hg clone -r Version-1.0 https://[email protected]/jisaacks/hgml https://[email protected]/jisaacks/hgml2
我收到此错误:
中止:无法创建新的 http 存储库
I am a little confused about how to rollback to a tag in Mercurial. (which I am very new to)
Say I have a tag called "Version-1.0" which was several revisions ago. lets say we are at r400 now
Now if my managers were to tell me they don't like the direction things have been going and basically want to ditch everything since that tag and go back to Version-1.0.
Well I can checkout that tag with:
hg update -r Version-1.0
Ok so now I am back to the version 1.0 tag, and if I were to never need to make a change this would be fine. However, as soon as I make a change and commit, I now have 2 heads (my new changes to Version-1.0 and r400 the stuff the managers want to ditch).
So now I need to merge with r400. I don't want to. (I don't really want to wipe all those changes off the earth, I would like them to remain in my history so I can go back to them later if management changes their mind again) but I currently don't want any of them.
What do I do?
update
An answer stated:
You could clone the entire repository up until the tag, then use that clone as your "new" central repository.
If my central repository is hosted by bitbucket, I am not sure how to do this. If the current one is at URL https://[email protected]/jisaacks/hgml
and I want to clone it up to the tag to a new repo named hgml2
(that doesn't exist yet) I tried this command locally on my machine:
hg clone -r Version-1.0 https://[email protected]/jisaacks/hgml https://[email protected]/jisaacks/hgml2
I get this error:
abort: cannot create a new http repository
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
登录bitbucket并点击右上角的“分叉”箭头图标。现在您可以打开“高级设置”以从标签中分叉。
然后,您可以将第一个存储库重命名为“myproject-abandoned-foo-changes”之类的名称,并重用分叉存储库的原始名称,您将在其中继续开发。
编辑:您还可以进行无操作合并。链接的维基页面解释说,这可能很糟糕,因为您的历史记录会受到不需要的更改的污染,但我认为在您的情况下,这可能正是您想要的,因为它将保留您的更改,同时避免“将所有内容切换到新的存储库” “您抱怨的问题。
Log on onto bitbucket and click the "Fork" arrow icon in the upper right corner. Now you can open the "advanced settings" to fork from a tag.
You could then rename the first repository to something like "myproject-abandoned-foo-changes" and reuse the original name for the forked repository, where you will continue development.
edit: you could also do a no-op merge. The linked wiki page explains that this might be bad because your history will be contaminated with the unwanted changes, but I think in your case this might be exactly what you want as it would preserve your changes while avoiding the "switching everything to a new repo" issue you complain about.
您可以使用
hg revert
。以下命令将您的存储库恢复到某个标签并放弃所有本地更改。You can use
hg revert
. The following command restores your repository to a certain tag and discards all local changes.在现代 Mercurial 中执行此操作的“正确”方法是关闭分支:
虽然这最初是为了关闭命名分支而添加的,但它对于匿名分支(OP 具有的分支)同样适用。特别是,它只会影响它所提交的头,而不影响同一命名分支上的任何其他头。
The "correct" way to do this in modern Mercurial is to close the branch:
While this was originally added to close named branches, it works equally well with anonymous branches (what the OP has). In particular, it will only affect the head it is committed on, and not any other heads on the same named branch.