Git入门指南十:应用标签

来源:互联网 发布:mssql查询分析器下载 编辑:程序博客网 时间:2024/06/07 18:19

十四. 应用标签

Git tag参数:用法:git tag [-a|-s|-u <key-id>] [-f] [-m <说明>|-F <文件>] <标签名> [<头>]或:git tag -d <标签名>...或:git tag -l [-n[<num>]] [--contains <提交>] [--points-at <对象>] [<模式>...]或:git tag -v <标签名>...-l, --list 列出tag名称-n[<n>] 每个 tag 信息打印 <n> 行-d, --delete 删除 tags-v, --verify 验证 tagsTag 创建选项-a, --annotate 注解 tag,需要一个说明-m, --message <说明> tag 说明-F, --file <文件> 从文件中读取提交说明-s, --sign 注解并 GPG 签名的 tag--cleanup <模式> 设置如何删除提交说明里的空格和#注释-u, --local-user <key id>使用另外的私钥签名 tag-f, --force 如果存在,替换现有的 tag--column[=<风格>] 以列的方式显示 tagTag 列表选项--contains <提交> 只打印包含提交的tags--points-at <对象> 只打印tags对象 

14.1 查看标签

git tag –l <name> , <name>支持通配符

# 查看某个tagbixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/workspace2/spark$ git tag -l v2.2v2.2#列出所有的tag名称bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/workspace2/spark$ git tag -lv2.2#查看某个tag的详情(有问题)bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/workspace2/spark$ git tag -v v2.2object 2c2e8b14d37d26c85fd07a5d21620f51eaad01fetype committag v2.2tagger xiaopeng.bxp <xiaopeng.bxp@****.com> 1378099160 +0800Release version v2.2

14.2. 新建标签

git tag –a -m 如果是需要给某个历史提交节点打标签,则加上对应hashcode即可

#1. 新建一个tagbixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/workspace2/spark$ git tag -a v2.2 -m "Release version v2.2"bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/workspace2/spark$ git tag -lv2.2#2. 把新建的分支push到远程bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/workspace2/spark$ git push origin v2.2Counting objects: 1, done.Writing objects: 100% (1/1), 169 bytes | 0 bytes/s, done.Total 1 (delta 0), reused 0 (delta 0)remote: To git@mirror.gitlab.****.com:/home/git/repositories/sospartan/spark.gitremote: * [new tag] v2.2 -> v2.2To git@gitlab.****:sospartan/spark.git* [new tag] v2.2 -> v2.2#扩展阅读$ git push origin –tags # 将本地所有标签一次性提交到git服务器

14.3. 删除标签

git tag –d<name>

#1. 删除本地tag v2.2bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/workspace2/spark$ git tag -d v2.2已删除 tag 'v2.2'(曾为 78fa3cc)bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/workspace2/spark$ git tag -lbixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/workspace2/spark$#2. 删除远程tagbixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/workspace2/spark$ git push origin :v2.2remote: To git@mirror.gitlab.****.com:/home/git/repositories/sospartan/spark.gitremote: - [deleted] v2.2To git@gitlab.****c.com:sospartan/spark.git- [deleted] v2.2

值得注意的是,如果tag名字和分支名字一样的时候,push需要指定refs的详细路径,因为分支和tag在git内部是这样表示的(只是引用),tag只存储所指向的那一次提交:

refs/tags/{tagnane} refs/heads/branches/{branchnane}

所以要这样push相同名字的tag和分支

$: git push origin refs/tags/product $: git push origin refs/heads/branches/product 

14.4. 提交标签

git push origin <分支名><tag name>

14.5. 恢复代码到某个标签点

git show<tagname> 由此得到对应的提交哈希值,然后git reset 回退代码


微信公众帐号: wirelessqa

wirelessqa

关于作者:

作者: 毕小朋 | 老 毕 邮箱: wirelessqa.me@gmail.com

微博: @WirelessQA 博客: http://blog.csdn.net/wirelessqa


0 0
原创粉丝点击