Tag
In Git, a tag is a reference to a specific point in the repository's history. Tags are used to mark important milestones or releases in the project's lifecycle. Unlike branches, tags are static and do not change once they are created.
Tags are commonly used for:
-
Versioning releases: When a new version of the software is ready for release, a tag is created to mark that specific point in the commit history. For example, when releasing version 2.3.1 of a project, a tag named
v2.3.1
can be created to reference the commit that represents this release.The prefixv
is not required but often used to indicate that the tag represents a version number. This lets branches namedX.Y.Z
coexist with tags namedvX.Y.Z
. -
Marking important milestones: Tags can also be used to mark significant milestones in the project's development, such as the completion of a major feature or a critical bug fix. For instance, a tag named
feature-x-completion
can be created to mark the commit that introduces a new feature. -
Quick reference: Tags provide a convenient way to reference a specific point in the repository's history without having to remember or look up the commit hash. This is particularly useful when you need to quickly switch between different versions of the project.
Examples
Create a simple tag:
git tag v1.0.0
Create an annotated tag with a message:
git tag -a v1.2.0 -m "Release 1.2.0"
List all tags:
git tag
Check out a specific tag:
git checkout v1.2.0
Compare changes between a tag and the current HEAD:
git diff v1.2.0..HEAD