Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Git tags


May 25, 2021 Git


Table of contents


Git tags

If you reach an important stage and want to always remember that particular commit snapshot, you can tag it with a git tag.

For example, we want to release a "1.0" version for our w3cschoolcc project. We can label the latest commit (HEAD) "v1.0" with the git tag -a v1.0 command.

The -a option means "Create an annotation label." I t can be executed without the -a option, but it doesn't record when the label was typed, who hit it, and doesn't let you add a label annotation. I recommend creating annotation labels all the time.

$ git tag -a v1.0 

When you execute the git tag-a command, Git opens your editor and lets you write a tab annotation, just as you would a comment on a commit.

Now, notice that when we do git log --decorate, we can see our tags:

$ git log --oneline --decorate --graph
*   88afe0e (HEAD, tag: v1.0, master) Merge branch 'change_site'
|\  
| * d7e7346 (change_site) changed the site
* | 14b4dca 新增加一行
|/  
* 556f0a0 removed test2.txt
* 2e082b7 add test2.txt
* 048598f add test.txt
* 85fc7e7 test comment from w3cschool.cn

If we forget to tag a commit and publish it, we can tag it.

For example, let's say we published commit 85fc7e7 (the last line of the instance above), but forgot to label it then. We can now also:

$ git tag -a v0.9 85fc7e7
$ git log --oneline --decorate --graph
*   88afe0e (HEAD, tag: v1.0, master) Merge branch 'change_site'
|\  
| * d7e7346 (change_site) changed the site
* | 14b4dca 新增加一行
|/  
* 556f0a0 removed test2.txt
* 2e082b7 add test2.txt
* 048598f add test.txt
* 85fc7e7 (tag: v0.9) test comment from w3cschool.cn

If we want to see all the labels, we can use the following command:

$ git tag
v0.9
v1.0

Specify the label information command:

git tag -a <tagname> -m "w3cschool.cn标签"

PGP signature tag command:

git tag -s <tagname> -m "w3cschool.cn标签"