2

2Git, the concept

2.6

Tagging

Tagging is used to give a meaningful name to a commit point.

Tags are usually used to indicate a particular state or release of a project.

The following are the rules for a tag:

  1. Each tag must be unique; two separate commits cannot have the same tag

  2. Tags can be any combination of letters and numbers (but not spaces) see § 2.6.4 for specific restrictions

  3. Tags are not case sensitive

  4. A particular commit can have more than one tag

Git supports two types of tag: a lightweight tag and an annotated tag.

2.6.1

Lightweight tags

Lightweight tags are just simple labels that are attached to particular commit. The lightweight tag does not support an associated message and does not record any user information about who created it. It is literally just a label attached to a commit.

Lightweight tags are created using the tag command within Git. If no commit point is specified, the tag will be applied to the current head commit.

  • Lightweight tags are the only tags supported by Brackets-Git.

2.6.2

Annotated tags

Annotated tags do everything that lightweight tags do, but they contain additional information, they include a message (hence annotated) that is similar to a commit message, it includes information about the tag, e.g. first public release.

Annotated tags also record the username and email address of the person creating the tag as well as the date of its creation.

Annotated tags are created using the tag -a command within Git. If no commit point is specified, the tag will be applied to the current head commit.

Annotated tags are stored as full objects in the Git database; that is to say they are part of the revision history.

2.6.3

Using tags

Once created a tag can be used in place of the commit number (hash or SHA). This is true of both lightweight and annotated tags.

In the above example, the commit point [5493a7c] has been given the tag name V02.

The Git command to do a hard reset to this commit point is git reset 5493a7c --hard. Now that the commit point has a tag, the command git reset --hard V02 can be used instead.

I.e. when a commit is tagged, the tag name can be used to replace the commit number (note the change to the order, the tag is at the end, the commit number is in the middle).

2.6.4

Tag naming restrictions

Tags can be called pretty much anything you like; they can’t contain spaces though; this is the full list of restrictions:

Tag naming restrictions

Tags cannot begin or end with, or contain multiple consecutive / characters.

They cannot contain any of the following characters \, ?, ~, ^, :, * , [, @.

They cannot contain a space.

They cannot end with a . or have two consecutive .. anywhere within them.

Tags are not case sensitive.

In terms of my own conventions, I make the following restrictions:

  1. Use a dash instead of spaces

  2. Only use the characters [a-z], [A-Z], the numbers [0-9] and the
    dash/hyphen [-]

This is just my own preference you understand. Although it is a very safe one to use.



End flourish image