如何使用 git 獲取當前提交的標簽,或者如果標簽不存在,則獲取短提交 sha?
我一直在使用git describe --always,但由于某種原因它不再作業了,它現在回傳最后一個標簽幾周前帶有一些亂數和一些 sha。
? git describe --always
some-tag-1437-g9d3616e339
? git log
9d3616e339 [11 minutes ago] (HEAD -> master, origin/master, origin/HEAD) message
# ... bunch of other commits with no tags
81bbfc64e2 [8 weeks ago] (tag: some-tag) message
uj5u.com熱心網友回復:
如果您想獲得指向當前提交的標簽串列,請使用git tag --points-at:
git tag --points-at HEAD
git tag --points-at HEAD "v-*" # only keep tags starting with 'v-'
如果你想要一個標簽名或一個提交哈希,你可以添加一些腳本:
# in case there would be several tags: take the first one
name=$(git tag --points-at HEAD "v-*" | head -1)
# if no tag: get the short sha
if [ -z "$name" ]; then
name=$(git rev-parse --short HEAD)
fi
# do something with $name ...
echo $name
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/515226.html
標籤:混帐
