git 标签:致命:无法将“HEAD”解析为有效的引用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19116545/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:04:32  来源:igfitidea点击:

git tag: fatal: Failed to resolve 'HEAD' as a valid ref

git

提问by Ahmad

I am cloning a single branch from a repository and creating a tag in a python script. The commands are as follows.

我正在从存储库克隆一个分支并在 python 脚本中创建一个标签。命令如下。

git clone -b master --single-branch <repository adress>

git tag -a testag -m 'test'

It clones successfully but when it comes to adding the tag, it breaks with the following error:

它克隆成功,但在添加标签时,它因以下错误而中断:

fatal: Failed to resolve 'HEAD' as a valid ref.

回答by sebastianr

I ran into the same issue and was able to fix it by changing from

我遇到了同样的问题,并且能够通过更改从

git tag -a testtag -m 'test'

to

git tag -a testtag -m "test"

I was running in Windows 7. Hope this helps :-)

我在 Windows 7 上运行。希望这会有所帮助:-)

回答by Abdalla Mohamed Aly Ibrahim

I had the same issue. You have to commit first before tagging

我遇到过同样的问题。你必须在标记之前先提交

git commit

because you put tags on commits. So when there is no commit (like in your situation), you can't create a tag.

因为你在提交上放置了标签。因此,当没有提交时(例如在您的情况下),您无法创建标签。

回答by Mukesh

I also faced git tag: fatal: Failed to resolve 'HEAD' as a valid refissue when I was missing -m in the following command.(during tag creation)

git tag: fatal: Failed to resolve 'HEAD' as a valid ref当我在以下命令中缺少 -m 时,我也遇到了问题。(在标签创建期间)

git tag -a testtag 'test'

changing to

更改为

git tag -a testtag -m 'test'

fixed the issue

修复了问题

回答by arush436

I had the same problem. I cloned from a bare repo and tried to use 'git tag' in that cloned repo, and that is where I was getting the error. To fix it I had to at least one push up to master before I could begin tagging. Hope this helps.

我有同样的问题。我从一个裸仓库克隆并尝试在该克隆仓库中使用“git tag”,这就是我收到错误的地方。为了解决这个问题,我必须在开始标记之前至少进行一次推送以掌握。希望这可以帮助。

回答by raffi

If you have access to the remote repository

如果您有权访问远程存储库

cd /path/to/remote/repository
git config --bool core.bare true