In Git, tags are used to mark specific points in history as important. There are two main types of tags: lightweight and annotated. Lightweight tags are simply pointers to a specific commit, while annotated tags are full Git objects that contain metadata like the tagger name, email, date, and a tagging message. Annotated tags are generally recommended for releases because they provide more information.
In this step, we will create an annotated tag and then inspect it.
Make sure you are in the ~/project/my-time-machine
directory:
cd ~/project/my-time-machine
Now, let's create an annotated tag for our first commit. We'll call it v1.0
. Use the -a
flag to create an annotated tag and the -m
flag to provide a message:
git tag -a v1.0 -m "Initial version of the time machine message"
You should see no output if the command was successful.
To see the tags in your repository, use the git tag
command:
git tag
You should see:
v1.0
Now, let's use git cat-file
to see the type of our new tag:
git cat-file -t v1.0
You should see:
tag
This confirms that v1.0
is a "tag" object, which means it's an annotated tag.
Finally, let's use git show
to see the details of the annotated tag:
git show v1.0
You should see output similar to this:
tag v1.0
Tagger: Jane Doe <[email protected]>
Date: Mon Aug 7 10:05:00 2023 +0000
Initial version of the time machine message
commit a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9
Author: Jane Doe <[email protected]>
Date: Mon Aug 7 10:00:00 2023 +0000
Send a message to the future
diff --git a/message.txt b/message.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/message.txt
@@ -0,0 +1 @@
+Hello, Future Me
Notice that the output for an annotated tag includes information about the tag itself (tagger, date, message) in addition to the details of the commit it points to. This extra information is why annotated tags are preferred for marking significant releases.
You've now successfully created and inspected an annotated tag! This is a valuable skill for marking important milestones in your projects.