什么是标签
标签是版本库的快照,其实就是指向某个commit的指针。
tag是一个"固化的分支",一旦打上tag之后,这个tag代表的内容将永远不可变,因为tag只会关联当时版本库中最后一个commit对象。
分支的话,随着不断的提交,内容会不断的改变,因为分支指向的最后一个 commit 不断改变。所以一般应用或者软件版本的发布一般用 tag。
一、创建标签
1.创建带有说明的标签:git tag -a tagname -m "说明文字"
2.给指定的commit打标签:
# 找历史提交的commit id
git log --pretty=oneline --abbrev-commit
# 给指定的commit id打标签
git tag -a tagname commitID
二、查看标签
1.列出所有标签:git tag
2.列出所有标签及说明:git tag -n
3.搜索标签:git tag -l "1.0.*"
4.查看标签信息:git show tagname
三、删除标签
1.删除标签:git tag -d tagname
2.删除远程标签:git push origin --delete tag <tagname>
四、本地标签推送到远程
1.推送指定标签:git push origin tagname
2.次性推送全部尚未推送到远程的本地标签: git push origin --tags
五、重命名标签
1.删除原有tag,重新添加:
git tag -d <old-tag>
git tag -a <new-tag> -m "说明文字"
2.强制替换,再删除原有:
git tag -f <new-tag> <old-tag>
git tag -d <old-tag>
六、获取指定标签
1.获取指定tag代码:git checkout tagname
2.获取指定tag作为一个分支:git checkout -b branchname tagname