Quick Start Git...login
Quick Start Git Tutorial
author:php.cn  update time:2022-04-11 13:44:34

Git tags


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

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

-a option means "create an annotated label". It can be executed without the -a option, but it will not record when the tag was added or who added it, nor will it allow you to add a comment about the tag. I recommend always creating annotated tags.

$ git tag -a v1.0

When you execute the git tag -a command, Git will open your editor and let you write a tag comment, just like you write a comment for the submission.

Now, notice that when we execute 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.cc

If we forget to tag a commit, publish it again , we can append tags to it.

For example, suppose we published commit 85fc7e7 (the last line of the example above), but forgot to tag it at that time. We can also now:

$ 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.cc

If we want to view all tags, we can use the following command:

$ git tag
v0.9
v1.0

Specify tag information command:

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

PGP signature tag command:

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

php.cn