Git Tags
If you reach an important stage and want to remember that special commit snapshot forever, you can tag it with git tag.
For example, we want to release a "1.0" version for our w3cschoolcc project. We can use git tag -a v1.0
The command tags the latest commit (HEAD) with "v1.0". The
-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 a commit.
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 and publish it again, we can append tags to it.
For example, suppose we published commit 85fc7e7 (the last line in 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
PGP signature tag command:
git tag -s
The above is the detailed explanation of tags in the Git tutorial. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!