Tagging With Git

These are my notes on Tagging With Git.

Samsung Store on Amazon! If you buy something, I get a small commission and that makes it easier to keep on writing. Thank you in advance if you buy something.

 


Listing Tags
Tagging with git is the ability to mark specific points of interest in your
repositories. Usually, they will mark a significant change. To see existing
tags:

git tag

It just lists them in alphabetic order. You can search for tags that have some
meaning to you.

git tag -l "1.0.5"

This will list tags with this version number. You can also use wildcards to
search just like you would with anything else.

Creating Tags
There are two kinds of tags in Git. They are called lightweight and annotated. A
lightweight tag is like a branch that does not change, it is just a pointer to a
specific commit. Annotated tags are stored as objects in the Git database. They
are checksummed and include the tagger's name, email, and date. 

A lightweight tag is the commit checksum stored in a file. There is no other
information stored with it. To create a lightweight tag:

git tag "tag-name"

You can see the information on a specific tag like this:

git show "tag-name"

Creating annotated tags is just as easy. Use the -a flag when creating a tag,
this will provide more information with the tag. You can also provide a message,
like with a commit, with the -m flag. So:

git tag -a 1.0.2 -m "this is the version I worked on"

Now use the "show" command to see the information related to the tag.

git show 1.0.2

It shows all the information such as tagger, date, and the message with it.

Sharing Tags
By deafult, the "git push" command does not transfer tags to remote servers.
However, we can make this happen. You just have to tell the "push" command to do
so. 

git push origin "tag-name"

This will push a single tag to your remote. If you want to push many tags at
once, we just use:

git push origin --tags

This will push all the tags available. In fact, it will push both lightweight
and annotated tags. 

Deleting Tags
To delete a tag in your local repository, use the -d flag:

git tag -d "tag-name"

This will not remove the tag from remote servers. To delete a tag from a remote
server, use:

git push origin --delete "tag-name"

Checking Out Tags
If you want to view the versions of files a tag is pointing to, you can use:

git checkout "tag-name"

It will say you are in "detached head" state. While pretty ominous sounding, it
simply means that if you make changes then create a commit, the tag will stay
the same. However, your new commit will not belong to any branch and be
unreachable except by the same commit hash. So, if you need to make any changes
to an older version, you need to create another branch.