Mercurial has a built-in help mechanism for all commands. In this case, hg help tag
shows:
options:
-f --force force tag
Let's add a tag and then move it:
$ hg init foo
$ cd foo/
$ touch a
$ hg add a
$ hg commit -m 'add a'
$ hg tag 0.1.0
What is the history?
$ hg log -G
@ changeset: 1:9352d8865ee5
| tag: tip
| summary: Added tag 0.1.0 for changeset a4cab63b7c86
|
o changeset: 0:a4cab63b7c86
tag: 0.1.0
summary: add a
Ahh, we changed our mind. We are missing one file. Let's add it (and so
add something to the hg history):
$ touch b
$ hg add b
$ hg commit -m 'add b'
We would like to move the 0.1.0 tag to the tip. Let's try:
$ hg tag 0.1.0
abort: tag '0.1.0' already exists (use -f to force)
Quite clear. Let's try again:
hg tag --force 0.1.0
What is the history ?
hg log -G
@ changeset: 3:04b62f2a9b16
| tag: tip
| summary: Added tag 0.1.0 for changeset 3d8bb8a977e6
|
o changeset: 2:3d8bb8a977e6
| tag: 0.1.0
| summary: add b
|
o changeset: 1:9352d8865ee5
| summary: Added tag 0.1.0 for changeset a4cab63b7c86
|
o changeset: 0:a4cab63b7c86
summary: add a
As we can see, the tag has moved to the new location.
For curiosity, how are tags stored? In a simple text file:
$ cat .hgtags
a4cab63b7c868638e51a45d93443b1a0eb56e1e4 0.1.0
a4cab63b7c868638e51a45d93443b1a0eb56e1e4 0.1.0
3d8bb8a977e6be693a30c30d7d7675d04623690f 0.1.0
If the .hgtags file has multiple entries with the same tag, the last one
wins. This is seen often when merging branches.
Left to the reader: clearly these changes are local. You have to push to
bitbucket to make them public.
EDIT
To answer the additional question: is there a way to remove a tag, or to rename a tag for the same commit ?
The safest way is not to rename the tag, it is to add the new tag name for the same commit (with hg tag -r REV). Said in another way: a single commit can have associated as many tags as you want.
It is also possible to remove the tag, simply by removing the corresponding line from .hgtags. This is delicate to get right, because there is one copy of that file per branch, and it could come back as the result of a merge.