Differences between revisions 32 and 33
Revision 32 as of 2009-08-19 17:47:34
Size: 5909
Comment:
Revision 33 as of 2009-11-12 21:03:29
Size: 5995
Editor: JeffSchiller
Comment:
Deletions are marked like this. Additions are marked like this.
Line 14: Line 14:

=== Example ===

$ hg tag this_is_my_tag
Line 110: Line 115:

  * Can you add an example please?

Tag

(Note: If you are migrating from CVS, please read this discussion of CVS tags before you continue.)

hg tags
hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...

A tag is a symbolic identifier for a changeset. It can contain any characters except ":" (colon), "\r" (Carriage Return) or "\n" (Line Feed). Mercurial has two kinds of tags: local and regular.

A local tag is a convenience identifier that is not revision controlled, does not propagate with other changes, and lives in the .hg/localtags file in a repository.

A "regular" tag (with no special specifier) is revision controlled, does propagate with other changes, and lives in the .hgtags file in a repository.

Example

$ hg tag this_is_my_tag

How do tags work in Mercurial?

Tags work slightly differently in Mercurial than most revision systems. The design attempts to meet the following requirements:

  • be version controlled and mergeable just like any other file

  • allow signing of tags
  • allow adding a tag to an already committed changeset

  • allow changing tags in the future

Thus Mercurial stores tags as a file in the working dir. This file is called .hgtags and consists of a list of changeset IDs and their corresponding tags. To add a tag to the system, simply add a line to this file and then commit it for it to take effect. The hg tag command will do this for you and hg tags will show the currently effective tags.

Note that because tags refer to changeset IDs and the changeset ID is effectively the sum of all the contents of the repository for that change, it is impossible in Mercurial to simultaneously commit and add a tag for the changeset being committed. Thus tagging a revision must be done as a second step. Thus, as above, the only changesets that can be tagged are ones already committed.

The fact that tags identify changesets and are also parts of changesets has some potentially confusing implications:

  • The changeset that a tag refers to is always older than the changeset that commits the tag itself.
  • Updating a working dir to a particular tag will take that directory back to a point before the tag itself existed.

  • Cloning a repo to a particular tag will give you a new repo that does not have that tag.

<!> Common wisdom says that to avoid the confusion of a disappearing tag, you should clone the entire repo and then update the working directory to the tag. Thus preserving the tag in the repo.

What if I want to just keep local tags?

You can use "hg tag" command with an option -l or --local. This will store the tag in the file .hg/localtags, which will not be distributed or versioned. The format of this file is identical to the one of .hgtags and the tags stored there are handled the same.

How can tags been merged

Different tags coming e.g. from multiple branches sometimes (and surprisingly) may lead to a merge conflict. While mercurial knows about the logical contents of the file, it has forgotten it when doing a merge.

The safe way in case of a merge conflict is to take both sides.

How do tags work with multiple heads?

The tags that are in effect at any given time are the tags specified in each head. A difficult case arises, if the same tag specifies two different revisions in two different heads. There is no general "correct" solution to this problem.

If two definitions/changes of tags seem unrelated like in the following diagram, the "tipmost" (e.g. the one with the higher numeric revision number) wins.

In the above diagram tag_a refers to revision 2, since revision 14 is higher than revision 13.

/!\ Note that the numeric revision number depends on the sequence by which changes got pulled into a repository and may therefore vary even on repositories containing the same changesets.

However if a tag was defined in a common ancestor of both heads, but changed in just one head, the changed one wins over the unchanged one.

In the above diagram tag_b revers to revision 10, although revision 13 is not tip.

/!\ Note that this multiple-head tag collision resolution algorithm depends on the .hgtags-file to be append only and be carefully merged.

Local tags override all other tags.

See also: MultipleHeads

What if multiple lines with different revisions use the same tag name in .hgtags?

If there is just one head only the last line where the tag appears is taken into account. If there are multiple heads, the previous definitions of the tag are used to determine which head holds the most recent tag. See "How do tags work with multiple heads?". If a tag points to 0000000000000000000000000000000000000000 it is considered to be deleted.

The behavior is identical when this happens in .hg/localtags.

How do I remove a tag?

Either by

  • hg tag --remove tagname (this being the nearest equivalent to cvs tag -d)

  • adding tagname 0000000000000000000000000000000000000000 to the end of .hgtags

  • removing all references to tagname in .hgtags (but this might confuse the multiple-head tag collision resolution algorithm)

Help texts


CategoryCommand CategoryGlossary

  • Can you add an example please?

Tag (last edited 2013-09-01 02:00:16 by KevinBot)