首页·终端命令

git describe

git

用法

git describe [--tags] [--dirty]

以最近的标签为基准,把当前提交命名成 v1.2.0-5-gabc1234 这样;默认只看附注标签,轻量标签要加 --tags,一个标签都没有时要加 --always。

常用选项

选项含义
--tagsuse lightweight tags too, not just annotated ones
--dirtyappend -dirty when the working tree has changes
--alwaysfall back to a bare hash when no tag is found
--longalways the full tag-count-hash form
--abbrev=<n>how many hash digits to print
--match <pattern>only consider matching tags

示例

git describe --tags --dirty

prints something like v1.2.0-5-gabc1234-dirty

git describe --always

never fails, even in a repository with no tags

git describe --match "v*" --long

ignores tags that are not versions

难的地方在于撤销有好几种:把分支的指向挪走,和补一个反向提交,不是一回事。

怎么看

  • 方括号 [ ] 表示这部分可以不写。
  • 省略号 … 表示可以写多个。
  • 选项区分大小写——有些命令里 -r 和 -R 不是一回事。

常见问题

Q. git describe 是做什么的?

以最近的标签为基准,把当前提交命名成 v1.2.0-5-gabc1234 这样;默认只看附注标签,轻量标签要加 --tags,一个标签都没有时要加 --always。

Q. 怎么写?

git describe [--tags] [--dirty] —— 方括号表示可以省略的部分。

Q. 值得记的选项有几个?

这里列了 6 个,完整列表在 man git。这条命令属于git。

相关命令

man 手册: man git-describe