Easy Tutorial
❮ Git Remote Repo Git Reset ❯

Git Tags

If you reach an important milestone and want to remember that special commit snapshot forever, you can use git tag to mark it with a label.

For example, let's say we want to release version "1.0" of our tutorialpro project. We can tag the latest commit (HEAD) with the label "v1.0" using the command git tag -a v1.0.

The -a option stands for "create an annotated tag." You can execute the command without the -a option, but it won't record when the tag was created, who created it, or allow you to add a tag comment. I recommend always creating annotated tags.

$ git tag -a v1.0

When you run the git tag -a command, Git will open your editor and prompt you to write a tag comment, similar to how you comment on commits.

Now, note that when we run git log --decorate, we can see our tag:

*   d5e9fc2 (HEAD -> master) Merge branch 'change_site'
|\  
| * 7774248 (change_site) changed the tutorialpro.php
* | c68142b 修改代码
|/  
* c1501a2 removed test.txt, add tutorialpro.php
* 3e92c19 add test.txt
* 3b58100 第一次版本提交

If we forget to tag a commit and then release it, we can append the tag later.

For instance, suppose we released commit 85fc7e7 (the last line in the example above) but forgot to tag it at the time. We can do it now:

$ git tag -a v0.9 85fc7e7
$ git log --oneline --decorate --graph
*   d5e9fc2 (HEAD -> master) Merge branch 'change_site'
|\  
| * 7774248 (change_site) changed the tutorialpro.php
* | c68142b 修改代码
|/  
* c1501a2 removed test.txt, add tutorialpro.php
* 3e92c19 add test.txt
* 3b58100 (tag: v0.9) 第一次版本提交

To view all tags, you can use the following command:

$ git tag
v0.9
v1.0

To specify tag information:

git tag -a <tagname> -m "tutorialpro.org tag"

For PGP signed tags:

git tag -s <tagname> -m "tutorialpro.org tag"
❮ Git Remote Repo Git Reset ❯