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

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

git Warning: remote HEAD refers to nonexistent ref, unable to checkout

gitgitosis

提问by srboisvert

I'm trying to setup gitosis according to the instructions here.

我正在尝试根据此处的说明设置 gitosis 。

It works fine from my remote machine so the server seems to be setup fine but I'd also like to be able to do development on my gitosis server machine from a different user account (not the git user created in the gitosis setup).

它在我的远程机器上运行良好,因此服务器似乎设置得很好,但我也希望能够从不同的用户帐户(而不是在 gitosis 设置中创建的 git 用户)在我的 gitosis 服务器机器上进行开发。

I've copied the key and modified the gitosis.conf so that the other user account has access but when I try to clone it seems to work except at the end it says:

我已经复制了密钥并修改了 gitosis.conf 以便其他用户帐户可以访问但是当我尝试克隆它时它似乎可以工作,除了最后它说:

git Warning: remote HEAD refers to nonexistent ref, unable to checkout

and I end up with an empty directory except for .git

我最终得到了一个空目录,除了 .git

I've google for this a bit but have no real insight into what the problem is

我已经谷歌了一点,但没有真正了解问题所在

采纳答案by srboisvert

I found out what was going wrong. The problem was that I wasn't paying attention to the warnings when I was pushing to my gitosis server so I didn't realize that I wasn't pushing a particular branch. I had assumed it would just push the current but that isn't the case until you set:

我发现出了什么问题。问题是当我推送到我的 gitosis 服务器时我没有注意警告,所以我没有意识到我没有推送特定的分支。我原以为它只会推动电流,但在您设置之前情况并非如此:

git config push.default current

回答by Michael Krelin - hacker

  1. Do the git branch -rand git checkout -b master <remotebranchofinterest>

  2. Check the HEADfile in remote .git.

  3. Check if somebody already asked the question: here

  1. git branch -rgit checkout -b master <remotebranchofinterest>

  2. 检查HEAD远程 .git 中的文件。

  3. 检查是否有人已经问过这个问题:这里

回答by Boopathi Rajaa

One more possible cause for this warning might be that the masterbranch in the repository is missing (OR) the repository does NOT use a master branch. If this is the case, just don't worry about the Warning!, use

此警告的另一个可能原因可能是master存储库中的分支丢失(或)存储库不使用主分支。如果是这种情况,请不要担心警告!,使用

git checkout <some_existing_branch>

The warning is because, by default, after the pull git tries to checkout into the master branch.

警告是因为,默认情况下,在 pull git 尝试检出到 master 分支之后。

回答by Cristian Vrabie

Had a similar problem. It seems that on my first push I did git push origin master:/refs/heads/masterinstead of git push origin master:refs/heads/master(notice the extra slash). This caused my master to be placed (in the remote repository) at refs/heads/refs/heads/masterinstead of refs/heads/master. The fix was to reorganize the folders on remote and re-push.

有类似的问题。似乎在我第一次推动时我做了git push origin master:/refs/heads/master而不是git push origin master:refs/heads/master(注意额外的斜线)。这导致我的 master 被放置(在远程存储库中)refs/heads/refs/heads/master而不是refs/heads/master. 解决方法是重新组织远程文件夹并重新推送。

回答by Greg Bacon

Keep it simple. Add to gitosis authorization and SSH key for the user account on your server and clone as usual:

把事情简单化。为您服务器上的用户帐户添加 gitosis 授权和 SSH 密钥并照常克隆:

user@server$ git clone git@server:repo.git

回答by EvdB

If you are trying to clone over http://note that you need a git newer than 1.6.6 - otherwise you should use a git://based URI.

如果您尝试克隆,http://请注意您需要比 1.6.6 更新的 git - 否则您应该使用git://基于 URI。

回答by Dmitry O

I use tortoiseGit and I'm not aware of how to use git via the command line. So I always wonder how I can avoid such problem in my tortoise. So maybe I am not alone. I fixed the problem this way:

我使用 tortoiseGit,但不知道如何通过命令行使用 git。所以我总是想知道如何避免我的乌龟出现这样的问题。所以也许我并不孤单。我这样解决了这个问题:

  • clone the remote repo
  • right click on the root folder and from there choose an existing branch
  • 克隆远程仓库
  • 右键单击根文件夹,然后从那里选择一个现有的分支

Im my case, there was only a branch "dev", without master. So when I tried to clone there was no local branch to check out and as soon as I switched to "dev" it was able to check out all the content successfully. Hope that will be helpful.

我的情况是,只有一个分支“dev”,没有 master。因此,当我尝试克隆时,没有本地分支可以检出,一旦我切换到“dev”,它就能够成功检出所有内容。希望这会有所帮助。