How to untag in Bitbucket
Asked Answered
E

2

8

While the UI of Bitbucket allows to tag a given commit of a mercurial repository, I can't find a way (web-based or command-line) to remove the tag, which could be added by mistake (actually, there is no confirmation prompt to add it). When used to control releases, this kind of mistake might be a major problem.

Elanorelapid answered 20/9, 2017 at 5:55 Comment(3)
@cantSleepNow this is a mercurial question, not git.Twinflower
@Twinflower Yes, I saw that second after I voted to close, but I have then retracted the vote. Thx for pointing it out. When I click to close now it says You voted to close this question 6 hours ago You retracted your vote 6 hours ago weird... Maybe it was just the automatic comment that was left over...Outrank
@Outrank ah I see, no probs!Twinflower
T
2

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.

Twinflower answered 20/9, 2017 at 14:28 Comment(2)
Out of curiosity: is there any way to remove a tag? Or, assume that you've typed it in a wrong way (e.g. 0.1.=), and want to change the tag, for the same commit. How do you do that?Elanorelapid
@Elanorelapid I updated the answer to reflect this new question.Twinflower
C
2

Actually, it is possible to delete a tag. This can be done from the commit's view: the tag has a gray X next to it.

The tagged commit can be found on the commits' page. It is the top-most one for the tag.

Notes:

  • This answers the question "How to untag in Bitbucket" - I am using git, not mercurial.
  • I have still added the answer, because this page ranks high in search engine results.
Chewning answered 5/4, 2022 at 14:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.