In Git, Tag is a pointer used to mark a specific commit (commit), which is a static reference with a descriptive name. The following is a detailed explanation of Git Tag:
-
Create tags:
git tag
A Tag can be created using the command. For example,git tag v1.0.0
a Tag named v1.0.0 will be created.- Tag can point directly to a commit, or it can point to a specific branch.
-
Label type:
- Git has two types of Tags: Lightweight Tags and Annotated Tags.
- A lightweight tag is just a reference to a specific commit, with no additional information.
- An annotated tag is a self-contained Git object that contains additional information about the tag's author, date, comments, etc.
-
View Tags:
- Use
git tag
the command to list all tags. - Use
git show <tagname>
to view the detailed information of a specific Tag. - Use
git tag -l 'pattern'
to find matching Tags by pattern.
- Use
-
Switch to Tag:
- Use
git checkout <tagname>
to switch the working directory to a specific Tag. - Note that switching to Tag will put you in a "detached head pointer" state, meaning you will no longer be on any branch and your changes will not be saved.
- Use
-
Push and delete Tag:
- Use
git push origin <tagname>
the command to push the specified Tag to the remote warehouse. - Use
git push origin --tags
the command to push all local tags to the remote warehouse. - Use
git tag -d <tagname>
commands to delete local tags. - Use
git push origin :refs/tags/<tagname>
the command to delete the Tag on the remote warehouse.
- Use
By using Git's Tag function, we can mark important milestones, version releases or specific commits in the code base. Tag allows us to easily backtrack, view and manage the historical state of the code base. Hope this information helps you!