【发布时间】:2021-10-16 16:53:09
【问题描述】:
为了得到最新标签的提交,我在做
$(git rev-parse $(git describe --tags --abbrev=0))
但是如果根本没有标签,就会抛出错误fatal: No names found, cannot describe anything。
所以万一根本没有标签,我想得到第一次提交。我该怎么做?
$(git rev-parse $(git describe --tags --abbrev=0 || <?-- get the very first commit -->))
【问题讨论】:
-
我会抢先标记第一个提交;该标签要么被忽略(如果已经有更高版本的标签)要么防止
git rev-parse失败。 -
@chepner 哦,这很好。简单,但没有看到这个选项...