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:
Each tag must be unique; two separate commits cannot have the same tag
Tags can be any combination of letters and numbers (but not spaces) see § 2.6.4 for specific restrictions
Tags are not case sensitive
A particular commit can have more than one tag
Git supports two types of tag: a lightweight tag and an annotated tag.
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.
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.
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).
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:
Use a dash instead of spaces
Only use the characters [a-z], [A-Z], the numbers [0-9] and the
This is just my own preference you understand. Although it is a very safe one to use.