我有这个:
nodegit.Reference
.lookup(repo, `refs/tags/${tagName}`)
.then(ref => nodegit.Commit.lookup(repo, ref.target()))
.then(commit => ({
tag: tagName,
hash: commit.sha(),
date: commit.date().toJSON(),
}))
如果tagName只是提交的别名,则此代码有效,但是如果该标记是使用nodegit创建的正确标记,则会给我一个错误:
the requested type does not match the type in the ODB
当使用
git show [tagname]
时,它显示如下:tag release_2017-07-21_1413
Tagger: xxx
Date: Fri Jul 21 16:13:47 2017 +0200
commit c465e3323fc2c63fbeb91f9b9b43379d28f9b761 (tag: release_2017-07-21_1413, initialRelease)
那么,如何从该标记引用到提交本身(c465e)?
最佳答案
使用peel(type)
可以:
nodegit.Reference
.lookup(repo, `refs/tags/${tagName}`)
// This resolves the tag (annotated or not) to a commit ref
.then(ref => ref.peel(nodegit.Object.TYPE.COMMIT))
.then(ref => nodegit.Commit.lookup(repo, ref.id())) // ref.id() now
.then(commit => ({
tag: tagName,
hash: commit.sha(),
date: commit.date().toJSON(),
}))
关于javascript - 如何使用nodegit从标签名称获取提交信息?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45240808/