In the previous steps, we worked with an annotated tag. Now, let's explore lightweight tags. A lightweight tag is essentially just a pointer to a specific commit. It's like a branch that doesn't move. They are typically used for temporary or private tags.
Make sure you are still in the ~/project/my-time-machine
directory.
To create a lightweight tag, you simply use the git tag
command without the -a
or -m
options:
git tag experimental
This command creates a lightweight tag named experimental
that points to the current commit (the same commit that v1.0
points to).
Now, let's use git show
to see the details of this lightweight tag:
git show experimental
You should see output similar to this:
commit a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9
Author: Jane Doe <[email protected]>
Date: Mon Aug 7 10:00:00 2023 +0000
Send a message to the future
Notice that the output for git show experimental
is different from git show v1.0
. There is no "tag experimental" line, no Tagger information, and no tag message. git show
directly displays the commit that the lightweight tag points to.
To further confirm that experimental
is a lightweight tag, let's use git cat-file -t
:
git cat-file -t experimental
This time, the output should be:
commit
This confirms that the experimental
tag directly refers to a "commit" object, unlike the annotated tag v1.0
which referred to a "tag" object.
Lightweight tags are useful for quick, temporary markers in your repository. For example, you might use them to mark a specific commit you want to easily reference later, without needing to create a full annotated tag with a message.
You now understand the difference between annotated and lightweight tags and how to use git show
and git cat-file
to inspect them.