git 警告:远程 HEAD 指的是不存在的引用,无法结帐

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

warning: remote HEAD refers to nonexistent ref, unable to checkout

git

提问by skerit

This seems like a popular error for different causes.

对于不同的原因,这似乎是一个流行的错误。

I've got a simple bare git repo called "kiflea.git", I clone it like this:

我有一个简单的裸 git 存储库,名为“kiflea.git”,我像这样克隆它:

git clone git://kipdola.be/kiflea.git

Then git tells me: warning: remote HEAD refers to nonexistent ref, unable to checkout.

然后 git 告诉我: warning: remote HEAD refers to nonexistent ref, unable to checkout.

And yes, there are no versioned files in the map, except for the .git directory. Anyway, the only thing I need to do is:

是的,地图中没有版本化文件,除了 .git 目录。无论如何,我唯一需要做的是:

cd kiflea
git checkout master

And it works, all the files are there. But I thought cloning a repo automatically checks out the master, so what is going on exactly, and how do I fix it?

它有效,所有文件都在那里。但我认为克隆 repo 会自动检查 master,那么到底发生了什么,我该如何解决?

I have noticed that, after I do the git checkout masterbit, this gets added to my local .git config file:

我注意到,在我做完之后git checkout master,这会被添加到我的本地 .git 配置文件中:

[branch "master"]
    remote = origin
    merge = refs/heads/master

It's probably interesting to know that this git repository used to be an svn repository in a distant past.

知道这个 git 存储库在遥远的过去曾经是一个 svn 存储库,这可能很有趣。

Ps: when browsing the bare repository using gitweb, there clearly is a masterbranch there: http://kipdola.be/gitweb/?p=kiflea.git;a=summary

Ps:使用gitweb浏览裸仓库时,明显有一个master分支:http: //kipdola.be/gitweb/?p=kiflea.git;a=summary

回答by Mikko Rantalainen

The warning: remote HEAD refers to nonexistent ref, unable to checkout.means that the remote (bare) repository contains branch reference in the file called HEADthat does not match any published branch in the same repository.

warning: remote HEAD refers to nonexistent ref, unable to checkout.意味着远程(裸)存储库在调用的文件中包含HEAD与同一存储库中的任何已发布分支不匹配的分支引用。

Note that the warning only means that git didn't do checkout. The cloned repository is otherwise just fine.Just do git branch -ato see possible branches and git checkout the-branch-you-wantto workaround the issue.

请注意,警告仅表示 git 没有进行结帐。否则克隆的存储库就好了。只是git branch -a为了查看可能的分支并git checkout the-branch-you-want解决问题。

This usually happens because the default contents for that file (.git/HEADor plain HEADfor bare repositories) is ref: refs/heads/masterwhich says that if somebody is going to clonethis repository, they should by default clone the branch refs/heads/master. By default Git will create local branch without the refs/heads/prefix (that is, masterby default). Try git help symbolic-reffor more information.

这通常发生是因为该文件的默认内容(.git/HEADHEAD裸存储库的普通内容)ref: refs/heads/master表示,如果有人要访问clone此存储库,则默认情况下他们应该克隆 branch refs/heads/master。默认情况下,Git 将创建没有refs/heads/前缀的本地分支(即master默认情况下)。尝试git help symbolic-ref获取更多信息。

The problem with this situation is that Git does not provide a method for modifying remotesymbolic refs so either you use something the Git hosting provider has implemented (e.g. Settings - Default branch in GitHub if you have admin rights) or you have to use branch name masteras the default branch (because that's the default value for that symbolic ref).

这种情况的问题在于 Git 不提供修改远程符号引用的方法,因此您要么使用 Git 托管提供商已实现的内容(例如,如果您具有管理员权限,则使用 GitHub 中的设置 - 默认分支),或者您必须使用分支名称master作为默认分支(因为这是该符号引用的默认值)。

If you have shell access to your remote git repo, you can simply cd path/to/bare/git/repo; git symbolic-ref HEAD refs/heads/XYZwhere XYZis the branch name you want to use by default.

如果你有你的远程git仓库shell访问,你可以简单地cd path/to/bare/git/repo; git symbolic-ref HEAD refs/heads/XYZ在那里XYZ是你想用默认使用分支名称。

One way to hit this issue is to create a new remote bare repo with no commits and then do git push name-of-the-remote my-special-branch-namewhich will result in bare repository containing a single branch my-special-branch-namebut the HEADsymbolic ref still contains the default value pointing to master. As a result, you'll get the aforementioned warning.

解决此问题的一种方法是创建一个没有提交的新远程裸git push name-of-the-remote my-special-branch-name仓库,然后这样做将导致裸仓库包含单个分支,my-special-branch-nameHEAD符号 ref 仍包含指向master. 因此,您将收到上述警告。

回答by Marco Bonifazi

I have had the same issue because I was not using anymore the masterbranch and it went lost in both my local and remote repository.

我遇到了同样的问题,因为我不再使用该master分支,并且它在我的本地和远程存储库中都丢失了。

The remote repository had still the HEADset to master, I have changed it to one of the remote branch I actually use and everything works fine.

远程存储库仍然HEAD设置为master,我已将其更改为我实际使用的远程分支之一,一切正常。

If you can access your remote repository:

如果您可以访问远程存储库:

  • Go to your remote_repo.git;
  • Edit HEADfile
  • Change ref: refs/heads/masterto ref: refs/heads/your_branch
  • 去你的remote_repo.git;
  • 编辑HEAD文件
  • 更改ref: refs/heads/masterref: refs/heads/your_branch

回答by pal4life

Yes this is related to your git clone trying to checkout a branch different than master. Just do this

是的,这与您的 git clone 尝试签出不同于 master 的分支有关。就这样做

git clone user@git-server:project_name.git -b branch_name /some/folder

This will help you clone the exact branch via its branch name.

这将帮助您通过分支名称克隆确切的分支。

回答by adswebwork

Even though this error was displayed - my project was still connected to the corresponding repository - I ran the git branchcommand and saw the appropriate branches - then I ran git checkout *branchnameand BOOM - all was well.

即使显示了这个错误——我的项目仍然连接到相应的存储库——我运行了git branch命令并看到了相应的分支——然后我运行了git checkout *branchnameBOOM——一切都很好。

回答by Jason Axelson

There's definitely something wrong with your remote repository. You might be able to fix it by making a new clone of the repository. Also pushing a new commit to the master branch might work too.

您的远程存储库肯定有问题。您可以通过创建存储库的新克隆来修复它。将新提交推送到 master 分支也可能有效。

回答by Philip Oakley

I'd guess that it's the leading *in the commit log that is somehow fooling the remote server.

我猜想它是*提交日志中的领先者,以某种方式欺骗了远程服务器。

I can browse around the repo's web interface using some of the menu links, but others fail with a 404 - Unknown commit objector similar, particularly from the summary page.

我可以使用一些菜单链接浏览 repo 的 Web 界面,但其他人会失败404 - Unknown commit object或类似,特别是从摘要页面。

See if you can amend that last commit message and then force push the update to see if that fixes it. There may be a bug in the server demon. If it does fix it it would be worth reporting on the git list [email protected] (plain text messages only)

看看您是否可以修改最后一条提交消息,然后强制推送更新以查看是否可以修复它。服务器恶魔中可能存在错误。如果它确实修复了它,那么值得在 git 列表 [email protected] 上报告(仅限纯文本消息)

回答by Corrado

I had same issue when creating a bare repo.

创建裸仓库时我遇到了同样的问题。

I solved it just cloning the repo, creating a local master branch and then pushing master to the remote repo.

我只是通过克隆 repo,创建一个本地 master 分支,然后将 master 推送到远程 repo 来解决它。

1) clone the repo

1)克隆回购

$ git.exe clone --progress -v "the remote path" "my local path"

2) create a master branch locally.

2)在本地创建一个master分支。

   $ git checkout -b master

3) commit something in the local branch

3)在本地分支提交一些东西

$ git add readme.md 
$ git commit –m “Added readme”

4) Push local master on the remote

4)在远程推送本地master

   $ git push origin master

回答by brendan

I seemed to fix it with:

我似乎用以下方法解决了它:

git checkout -b  master
git push

This created the default master, and then I could checkout my other branches

这创建了默认主,然后我可以结帐我的其他分支

回答by Samantha

If there is no master branch actually available, check the following; If there is a file named 'packed-refs' inside the '.git' folder, open it and you could find all references listed.

如果没有实际可用的主分支,请检查以下内容;如果“.git”文件夹中有一个名为“packed-refs”的文件,打开它,你可以找到列出的所有引用。

Something like below;

像下面这样的东西;

# pack-refs with: peeled fully-peeled 
e7cc58650190bd28599d81917f1706445d3c6d8b refs/tags/afw-test-harness-1.5
^cfae4f034e82591afdf4e5ed72279297d0eee618
6afe1bcfa4bd74de8e0c8f64d024e1cc289206df refs/tags/afw-test-harness-2.1
^c32f7fa495d4b44652f46c065fcd19c3acd237a6
72f2e4284dfbf27c82967da096c6664646bbdd19 refs/tags/android-1.6_r1
^50992e805e758e2231f28ec2127b57a1a9fd0ddc
0cbd528cad1cee9556098b62add993fc3b5dcc33 refs/tags/android-1.6_r1.1

Then use;

然后使用;

git checkout refs/tags/xxxx

Or

或者

git checkout 'HASH value'

to checkout the required version. Thank you.

签出所需的版本。谢谢你。