介绍
在很多git仓库中,发布版本中会在源码里面嵌入版本信息。比如 IDF 发布版本 v2.1,那如何将 v2.1 显示在源码中呢?
例如: esp-idf
下,esp-idf/make/project.mk
中嵌入了一下代码。
IDF_VER := $(shell cd ${IDF_PATH} && git describe --always --tags --dirty)
该命令会获取当前仓库当前的 commit 对应的最近的 tag。
git-describe - Describe a commit using the most recent tag reachable from it
–always
Show uniquely abbreviated commit object as fallback.
–tags
匹配远程的 refs/tag
Instead of using only the annotated tags, use any tag found in refs/tags namespace. This option enables matching a lightweight (non-annotated) tag.
–dirty
–dirty 意味着如果源码如果被修改了(git status),则会在版本后面加上 -dirty (默认),如版本为 v2.1 , 如果你修改了源码,则git