系统学习 Linux 学习路径:从文件与进程到排障与安全

git-describe

根据最近的标签描述当前提交

补充说明

git describe 从最近的 tag 推导版本字符串,常用于构建版本号、制品命名和发布脚本。它依赖标签历史,浅克隆或没有 tag 时会退化。

常用示例

git describe --tags
git describe --tags --always
git describe --tags --dirty
git describe --tags --long
git describe --tags --match 'v*'
git describe --tags --exact-match
git describe --tags --abbrev=12 HEAD
git describe --tags --first-parent

易错点与排错

相关命令

参考链接

读完自测

合上页面,先回答,再展开对照。

  1. git describe 默认使用哪种标签?轻量标签怎么办?
  2. 仓库没有可用标签时,脚本怎样避免 describe 失败?
  3. 工作区有未提交改动时,为什么版本字符串仍可能看起来是干净的?
答案
  1. 默认只使用 annotated tag;轻量 tag 需要加 --tags。
  2. 加 --always,退回短哈希。
  3. 因为没有加 --dirty;只有加上它才会显示未提交改动的后缀。
微信小程序码:扫码打开命令速查小程序

小程序版

微信扫码,随时查命令