对于发行版,我通常使用v1.1.0之类的标签。在构建脚本期间,我正在创建一个包含当前git信息的fwVersion.c文件。目前,我已经提交了文件,并在文件中包含了分支信息,但是我想添加标签。
这可能吗?
Answers:
检查文档git describe。它找到与给定提交最接近的标签(即指向该提交的祖先的标签),并根据标签描述该提交。
如果您只想知道提交是否由标签指向,则可以检查以下内容的输出:
git describe --exact-match <commit-id>
git describe --all --exact-match `git rev-parse HEAD`
git describe --tags --abbrev=0 REV当您不希望标签上出现垃圾时,此功能将非常有用。
git describe --all(针对当前已签出的提交)或git describe --all <commit>一直以来几乎完成了我想要的所有操作。
您可以在手册中找到此信息
git tag --contains <commit>
我找到了两个最佳答案的组合,可以给我我想要的东西:
git describe --tags --exact-match <commit-id>
这将为您提供仅适用于该提交和不带注释的标签。当您想查找标签而又不必担心剥离格式时很有用(例如,对于Jenkins)。
例如。 $ git describe --tags --exact-match head~2
给你:
$ ReleaseBeta
合并一些答案:
git tag --contains [<ref>]
和
git tag --points-at [<ref>]
要不就
git tag
行为相同,为指定的ref或当前提交(如果未指定)打印任何(和所有)标签。
git describe --tags [<ref>]
其中<ref>默认为当前提交,如果没有与该提交关联的标签,则以128退出,并打印与该提交关联的标签(似乎不是一种模式)。
git describe [<ref>]--tags除了只打印带注释的标签外,其
行为与相同。
提供选项--contains,以describe将其打印与指定提交的祖先相关的标签。例如
$ git init
Initialized empty Git repository in /tmp/test
$ git commit -m one --allow-empty
[master (root-commit) 7fdfff2] one
$ git commit -m two --allow-empty
[master cd5f8f1] two
$ git tag -am foo foo
$ git tag bar
$ git log --format=oneline
cd5f8f1f4f29eb164f83e224768ccaf37fe170ed (HEAD -> master, tag: foo, tag: bar) two
7fdfff2ce5e3347f8eee4c9f2413dbd4e90060e1 one
$ git describe 7fdfff2ce5e3347f8eee4c9f2413dbd4e90060e1
fatal: No tags can describe '7fdfff2ce5e3347f8eee4c9f2413dbd4e90060e1'.
Try --always, or create some tags.
$ git describe --contains 7fdfff2ce5e3347f8eee4c9f2413dbd4e90060e1
bar~1
git describe --tags <commit-id>用于未注释的标签