![Git In-depth](https://static.frontendmasters.com/assets/courses/2018-02-20-git-in-depth/thumb.webp)
Check out a free preview of the full Git In-depth course
The "Tags & Annotated Tags" Lesson is part of the full, Git In-depth course featured in this preview video. Here's what you'd learn in this lesson:
Nina discusses tags, which is another type of reference. Lightweight tags are simple points to a commit. An annotated tag points to commit and stores additional information such as author, message, and date.
Transcript from the "Tags & Annotated Tags" Lesson
[00:00:00]
>> Nina: One of the other types of refs that we can have is a lightweight tag. Those are just a simple pointer to a commit. They get created when you create a tag with no arguments. It just captures the value in HEAD. So I'm on my tech post branch, now I check out master.
[00:00:21]
That means that HEAD moved back to the initial commit, the commit that master is pointing to. When I create that tag, my first commit, it just points to the value in HEAD.
>> Nina: In this case, the particular commit that HEAD is pointing to, so cd0. There's one other type of tag that we can create, and that's called an annotated tag.
[00:00:51]
They're created with git tag -a. So just like lightweight tags, they also point to a commit. But they also store additional information, like the author, the message and the date. So to create an annotated tag you do tag -a. I put version 1.0. You can pass in -m, just like a commit, to specify a message.
[00:01:22]
So my message is Version 1.0 of my blog. Now, I list my tags by running git tag. That shows me all the tags that are currently in my repository. So we have my first commit, which is the lightweight tag that we created previously. And we also have version 1.0, which is the annotated tag that we just created.
[00:01:47]
To look at the annotated tag and get all that useful information out, the author, the message, and the date, we do git show and the tag name. Git show version 1.0 will give us all the information about that tag. In practice, lightweight tags are not used very much.
[00:02:06]
Maybe you can use them to leave tags for yourself. But generally, you won't really see them being used in practice. Annotated tags are much more useful. To work with tags, there's just a few simple commits. We git tag to show all the tags in the repo to list them.
[00:02:31]
If we wanna list all the tags but also what commit they're pointing to, we do git show-ref --tags. That's a pretty useful command. If we wanna list all the tags that are pointing at a specific commit, there is a --points-at flag. So git tag --points-at <<commit> and it will show you all the tags pointing at a particular commit.
[00:03:02]
If we want to look at the tag; git show <tag-name>.
>> Nina: When talking about tags and branches, there's two important pieces of information that separate what a tag is and what a branch is. A branch, when you're on a branch, the current pointer, the branch pointer, it moves with every new commit to the repository.
[00:03:34]
So you use branches when your branch will change, when new commits will be added. Tags are a pointer to a commit. It's a snapshot. Tags aren't meant to change. You tag version one of your release, then version two. You don't move a tag to another commit.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops