git fatal:没有标签可以描述
我通过将标签应用于夜间构建来使用标签。然后,我想使用 describe --tags --match
的输出来告诉我图像距离夜间构建有多远。这是用于 QA 测试的。
我刚刚在比当前标签更旧的克隆中遇到错误。我运行了 git fetch --tags,所以我在 git tag 输出中看到了标签,但是当我运行 git describe --tags --match
I am using tags by applying them to nightly builds. Then later, I want to use the output of describe --tags --match <latest tag>
to tell me how far from the nightly build my images are. This is for QA testing.
I just ran into an error in a clone that is older than the current tag. I ran git fetch --tags, so I see the tag in git tag output, but when I run git describe --tags --match <tagname>
, I get fatal: No tags can describe <head sha1 version number>
. I cannot do a git pull to update the workspace at this point. Why does this happen and is there a workaround? Thanks very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我刚刚使用
git version 2.8.3
和命令gitdescribe --abbrev=0
遇到了这个错误。问题是,虽然标签存在于源中并且我的本地存储库是最新的,但标签没有提交消息。
在我用标签消息重新标记提交后,错误得到解决:
I just ran into this error with
git version 2.8.3
and commandgit describe --abbrev=0
.The problem was that while the tag existed in the origin and my local repository was up to date, the tag did not have a commit message.
The error was resolved after I re-tagged the commit with a tag message:
另一种解释可能是存储库是使用
depth=xyz
设置进行克隆的(Travis 默认情况下是这样的)。在这种情况下,历史记录可能会在最新标签之前被切断。从技术上讲,使用深度=xyz克隆会创建一个浅克隆,其中的条目描述了在哪里切断历史记录。当 git describe 遍历历史记录时,它可能会到达该分界点并停止搜索标签。如果您在使用 git fetch --tags 进行初始浅克隆后手动获取标签,甚至会发生这种情况。
如果这是问题所在,您需要
unshallow
存储库(或者首先创建一个完整(足够)的克隆)。请参阅 如何将 Git 浅克隆转换为完整克隆? 来解决问题。Another explanation can be that the repository was cloned with a
depth=xyz
setting (which Travis does by default). In that case, the history might be cut off before the most current tag.Technically, cloning with
depth=xyz
creates a shallow clone with entries in.git/shallow
that describe where to cut off history. Whengit describe
then walks the history it might get to that cut-off point and stops searching for a tag. That even happens if you fetched tags manually after the initial shallow clone withgit fetch --tags
.If this is the problem, you need to
unshallow
the repository (or create a full (enough) clone in the first place). See How to convert a Git shallow clone to a full clone? to solve the problem.发生这种情况是因为您只获取标签,而不是标签的提交历史记录。
git describe
使用此历史记录,这就是它出现错误的原因。唯一的解决方法是使用 git fetch来获取包含您感兴趣的标签的存储库历史记录。
It happens because you only fetch the tag, not the commit history of the tag.
git describe
uses this history, which is why it has an error.The only workaround is to fetch repo's history containing the tag you're interested in, using
git fetch <remote-name>
.这可能有两个原因。
actions/checkout
时缺少fetch-depth: 0
,因为它需要上一个标记提交之前的历史记录,如果您进行浅层提取,则可能会丢失该历史记录。There might be 2 reasons for this.
fetch-depth: 0
is missing while usingactions/checkout
since it requires the history upto the previous tag commit which might miss if you are doing shallow fetch.git pull
and push those changes to the remote and see if it is working.当我基于 git 引用创建 git 标签时,我实际上遇到了这个错误。
看来 git 引用不是“在 master 中”,这会导致一些问题。
因此,解决方法是在 master 中找到正确的提交引用并重新创建标签。
I actually ran into this error when I have created a git tag based on git reference.
It seems that the git reference was not "in master" and this cause some problems.
So the fix was to find the proper commit reference in master and recreate the tag.
对我来说,它在使用 git pull 而不是 git fetch 后起作用。
增强已提供的解决方案:我的 git 标签已经有标签消息,并且 git fetch对我的情况也没有帮助。
For me it worked after using
git pull
instead ofgit fetch
.Enhancing on the solutions already provided: My git tag already had a tag message and
git fetch <remote-name>
didn't help in my case as well.我在进行 git checkout 时使用下面的标签解决了这个问题。
获取深度:'0'
I have solved this issue with using below tag while doing git checkout.
fetch-depth: '0'