YouTip LogoYouTip

Git Tag

# Git Tags If you reach an important milestone and want to permanently remember the snapshot of that commit, you can use `git tag` to assign a tag to it. Git tags are used to mark specific points in a repository’s history, typically for releases (e.g., v1.0, v2.0). For example, if we want to release version "1.0" of our project, we can use the command `git tag -a v1.0` to assign the tag "v1.0" to the most recent commit (HEAD). **The `-a` option means** β€œcreate an annotated tag.” You can execute the command without the `-a` option, but then it won’t record when the tag was created, who created it, or allow you to add a tag annotation. We recommend always creating annotated tags. **Tag syntax format:** git tag For example: git tag v1.0 The `-a` option adds an annotation: $ git tag -a v1.0 When you execute `git tag -a`, Git opens your editor to let you write a tag annotation, just like writing a commit message. Now, notice that when we run `git log --decorate`, we can see our tags: * d5e9fc2 (HEAD -> master) Merge branch 'change_site'| | * 7774248 (change_site) changed the .php * | c68142b Modify Code|/ * c1501a2 removed test.txt、add .php * 3e92c19 add test.txt * 3b58100 First Version Commit If we forget to tag a particular commit and have already published it, we can retroactively add a tag. For instance, suppose we published commit `85fc7e7` (the last line in the example above), but forgot to tag it at the time. We can now do the following: $ git tag -a v0.9 85fc7e7 $ git log --oneline --decorate --graph * d5e9fc2 (HEAD -> master) Merge branch 'change_site'| | * 7774248 (change_site) changed the .php * | c68142b Modify Code|/ * c1501a2 removed test.txt、add .php * 3e92c19 add test.txt * 3b58100 (tag: v0.9) First Version Commit To view all tags, use the following command: $ git tag v0.9 v1.0 ### Pushing Tags to a Remote Repository By default, `git push` does not push tagsβ€”you must explicitly push them. git push origin To push all tags: git push origin --tags ### Deleting Lightweight Tags Delete locally: git tag -d Delete remotely: git push origin --delete ### Annotated Tags Annotated tags store the creator’s name, email, date, and can include tag messages. Annotated tags are more formal and suitable for scenarios requiring additional metadata. Syntax for creating an annotated tag: git tag -a -m "message" For example: git tag -a -m ".comTag" PGP-signed tag command: git tag -s -m ".comTag" View tag information: git show ### Example Below is a comprehensive example demonstrating how to create, view, push, and delete tags. Create lightweight and annotated tags: git tag v1.0 git tag -a v1.1 -m ".comTag" View tags and tag information: git tag git show v1.1 Push tags to a remote repository: git push origin v1.0 git push origin v1.1 git push origin --tags # Push all tags ### Deleting Tags Delete locally: git tag -d v1.0 Delete remotely: git push origin --delete v1.0
← Git ServerGit Commit History β†’