git describe 失败并显示“致命:未找到名称,无法描述任何内容”。
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4916492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git describe fails with "fatal: No names found, cannot describe anything."
提问by Philipp
I'm using git 1.7.1 on Ubuntu 10.10 amd64, and I'm trying to extract the hash of my repository HEAD to use it in an automated version information that I compile into my project.
我在 Ubuntu 10.10 amd64 上使用 git 1.7.1,我试图提取我的存储库 HEAD 的哈希值,以便在我编译到我的项目中的自动版本信息中使用它。
In the past, this always worked by using
过去,这总是通过使用
git describe --tags
however, git is now throwing
然而,git现在正在抛出
fatal: No names found, cannot describe anything.
at me. Does anyone have a clue what that means?
对我。有没有人知道这意味着什么?
Google showed only few hits and no solution.
谷歌只显示了很少的点击量,没有解决方案。
回答by CB Bailey
If you want the id of your HEAD
then you don't need describe
, you should just use rev-parse
.
如果你想要你的 idHEAD
那么你不需要describe
,你应该使用rev-parse
.
git rev-parse HEAD
If you want an abbreviated hash you can use --short
.
如果你想要一个缩写的哈希,你可以使用--short
.
git rev-parse --short HEAD
If you want a "describe" to fall back to an abbreviated hash if it can't find any suitable tags, you can use --always
.
如果您希望“描述”在找不到任何合适的标签时退回到缩写哈希,您可以使用--always
.
git describe --always
回答by eater
It sounds like you're expecting git-describe
to include the most recent tag and number of commits since that tag. However, the fatal: No names found
message means you don't have any tagsin your repository. You need to have at least one tag in the commit history in order for git describe
to tell you the latest tag.
听起来您希望git-describe
包含自该标记以来的最新标记和提交次数。但是,该fatal: No names found
消息意味着您的存储库中没有任何标签。你需要在提交历史中至少有一个标签git describe
才能告诉你最新的标签。
Just guessing, but perhaps you tagged a commit somewhere else, but never pushed the tag upstream (maybe you pushed the commit upstream, tagged it later, and didn't repush?). Now a new clone of your upstream is giving you this error (since it doesn't have any tag). If that's the case, you could try git push --tags
from the repository that has the tag you want (where git describe
is doing what you expect). Then do git pull
on the repository that doesn't have the tag.
只是猜测,但也许您在其他地方标记了提交,但从未将标记推送到上游(也许您将提交推送到上游,稍后标记它,并且没有重新推送?)。现在上游的一个新克隆给了你这个错误(因为它没有任何标签)。如果是这种情况,您可以git push --tags
从具有您想要的标签的存储库中尝试(在哪里git describe
做您期望的)。然后git pull
在没有标签的存储库上做。
回答by Mike Pollitt
I have had this problem in a CI build environment where the CI tool was performing a shallow clone of the repository. This was frustrating, because in my development environment, the command
我在 CI 构建环境中遇到了这个问题,其中 CI 工具正在执行存储库的浅层克隆。这令人沮丧,因为在我的开发环境中,命令
git describe --tags
would give me output like
会给我输出
2.2.12-7-g8ec9d6c9
whereas in the build environment I would get the "fatal no names found" error. If I tried using the --always tag
而在构建环境中,我会收到“致命的未找到名称”错误。如果我尝试使用 --always 标签
git describe --tags --always
then I would simply get the hash of the latest commit, but not the most recent tag prior to that commit
然后我将简单地获取最新提交的哈希值,而不是该提交之前的最新标签
8ec9d6c9
Performing a git pull
in the build environment wouldn't help, because once the repo has been cloned shallowly, future pulls will not update the tags.
git pull
在构建环境中执行 a无济于事,因为一旦 repo 被浅克隆,未来的 pull 将不会更新标签。
The solution was to ensure that the initial clone of the repo in the build environment was not a shallow clone (i.e. the git clone
command was not used with --depth
, --shallow-since
or --shallow-exclude
parameters).
解决方案是确保构建环境中 repo 的初始克隆不是浅克隆(即该git clone
命令未与--depth
,--shallow-since
或--shallow-exclude
参数一起使用)。
回答by Danilo Bargen
This happens if you don't have any tags in your repository. If the repository doeshave tags, then you're in a shallow clone (this is the default in CI systems like TravisCI or GitHub Actions).
如果您的存储库中没有任何标签,就会发生这种情况。如果存储库确实有标签,那么您就处于浅克隆中(这是 TravisCI 或 GitHub Actions 等 CI 系统中的默认设置)。
To fetch the history (including tags) from within a shallow clone, run
要从浅克隆中获取历史记录(包括标签),请运行
git fetch --prune --unshallow
For example, in the case of GitHub actions:
例如,在 GitHub 操作的情况下:
- uses: actions/checkout@v2
- run: git fetch --prune --unshallow
Afterwards, git describe
should work again.
之后,git describe
应该再次工作。
回答by dheeraj tripathi
I had the similar issue while working on a CI job, the issue was git clone or checkout scm used did not fetch tags while cloning the repo.
我在从事 CI 工作时遇到了类似的问题,问题是 git clone 或 checkout scm 在克隆 repo 时没有获取标签。
Fetching without tags Fetching upstream changes from https://github.**********
不带标签的获取 从https://github获取上游更改.**********
You can enable fetch tags by selecting "Advanced clone behaviours" and then clicking on fetch tags ..
您可以通过选择“高级克隆行为”然后单击获取标签来启用获取标签。
回答by Stefan Profanter
If you came here due to this error message in Travis CI, you can use the following setting to avoid shallow clones:
如果你因为 Travis CI 中的这个错误信息来到这里,你可以使用以下设置来避免浅克隆:
git:
depth: false
I tested git fetch --tags
but that did not work.
我测试过,git fetch --tags
但没有用。
回答by vetalok
This command helped me: git fetch -t
这个命令对我有帮助: git fetch -t