10

I want to start using tags in Mercurial. I plan to have a "stable" tag that always points to the last good revision.

As I understand it, I can tag the current changeset via hg tag stable.

What's the proper way to move the tag? When I try to run hg tag stable again it tells me:

abort: tag 'stable' already exists (use -f to force)

And if I force it, I get this bug which has no resolution or comments. i.e., it duplicates the old tag. I don't even know why the tag needs to be in there more than once in the first place; I just want to update it to point to a single changeset.

4

3 回答 3

15

我还没有看到这样的标签移动操作,但它本质上是复制一些东西并删除原来的,所以:

hg tag --remove stable
hg tag -r newrevisionhash  stable

或者在您的标签上附加某种后缀,例如版本号。它还可以让您跟踪您的发布。

意见 1:我一直认为 Mercurial 更多的是保留历史,而在 git 下你可以更改某些内容,而在 Mercurial 中你必须改写它。

意见 2:标记稳定版本的另一种选择是将它们保留在一个分支中。我工作的地方default只有稳定的代码。所有其他工作都在孤立的分支中完成。

更新标签的脏单行:

current=`hg log -l1 --template '{node}'`; hg tag --remove stable; hg tag -r $current stable

似乎这种暴行甚至可以作为 Mercurial 别名添加到.hgrc

[alias]
movetag=!(current=`hg log -l1 --template '{node}'`; $HG tag --remove stable; $HG tag -r $current stable)

我捕获了当前提示的值,因为标签删除/添加本身就是提交,所以他们“移动”提示(看不到任何关于标签的错误tip——这只是为了精确起见)。当然有可能让它更漂亮,但那些对我有用。

于 2013-08-20T16:24:59.987 回答
7

Instead of having a tag that moves, you should use named branches instead. They function almost like a moving tag.

You write in a comment above that

All work is done on other branches, but we merge them into 'default' when they're ready and then perform integration testing. There's a period where 'default' may be fubar if there's a bad merge. Thus I want to keep a stable tag on default and only move it after the integration testing is complete/verified.

To solve this you need an extra named branch — call it stable. Then merge tested and approved changesets on default into stable in your own pace. It doesn't matter if default has changesets that are still being tested, when changeset X passes the tests, you do

$ hg update stable
$ hg merge X

to promote X as a stable changeset. Descendants of X (on default) remain unchanged, i.e., they are not yet marked stable.

于 2013-08-20T22:47:11.013 回答
4

正如@guessimtoolate 和@Martin Geisler 已经指出的那样,您可以使用命名分支来容纳所有好的修订(这也是我们在公司使用 hg 的方式)。另一种方法是使用书签,它充当附加到一个修订版的可移动标签。

于 2013-08-21T11:28:35.770 回答