开发者

Mercurial how to rollback to a tag?

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://jisaacks@bitbucket.org/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.开发者_StackOverflow中文版0 https://jisaacks@bitbucket.org/jisaacks/hgml https://jisaacks@bitbucket.org/jisaacks/hgml2

I get this error:

abort: cannot create a new http repository


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.


You can use hg revert. The following command restores your repository to a certain tag and discards all local changes.

hg revert -r tagname --all


The "correct" way to do this in modern Mercurial is to close the branch:

hg up head-i-dont-like
hg commit --close-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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜