Git clone:“您似乎克隆了一个空存储库”

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

Git clone: "You appear to have cloned an empty repository"

git

提问by user650261

Some colleagues and I have been working on a project stored in a private git repository. Historically, there have been no problems, but recently I attempted to clone, and got the following problem:

我和一些同事一直在研究存储在私有 git 存储库中的项目。从历史上看,没有问题,但最近我尝试克隆,遇到了以下问题:

Cloning into 'project'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.

A git logprovides:

Agit log规定:

fatal: your current branch 'master' does not have any commits yet

致命:您当前的分支“master”还没有任何提交

This isn't correct - my colleague pushed plenty of (nonempty) changes on Dec. 6 (although now that branch isn't showing on a --single-branch clone attempt). When he ssh's into the git repository, there is plenty of directory structure there.

这是不正确的 - 我的同事在 12 月 6 日推送了大量(非空)更改(尽管现在该分支未在 --single-branch 克隆尝试中显示)。当他 ssh 进入 git 存储库时,那里有很多目录结构。

So my questions:

所以我的问题:

  1. How could this have happened?
  2. How can we recover the repository? It seems the stuff is on the remote repo, but for some reason, it isn't aware that it's there.
  1. 这怎么会发生?
  2. 我们如何恢复存储库?似乎这些东西在远程仓库中,但出于某种原因,它不知道它在那里。

回答by Emile Bergeron

If the repo is hosted on a gitlab server, and you used git over httpto clone the repo, it could be related to this:

如果存储库托管在 gitlab 服务器上,并且您使用 git overhttp克隆存储库,则可能与此有关:

Git over HTTP will receive an empty repo if giltab-git-http-serveris not properly configured

如果giltab-git-http-server配置不正确,Git over HTTP 将收到一个空的 repo

If for some reason gitlab-git-http-serveris not properly configured, or you are using a custom nginx or Apache proxy that forwards directly to Unicorn and you attempt to clone via HTTP, the request succeeds, you receive a 200 and an empty repo.

如果由于某种原因gitlab-git-http-server未正确配置,或者您正在使用直接转发到 Unicorn 的自定义 nginx 或 Apache 代理,并且您尝试通过 HTTP 进行克隆,则请求成功,您会收到一个 200 和一个空的 repo。

A quick fixis to use git over sshto clone the repo.

一个快速的解决方法是使用git over ssh来克隆 repo。

回答by Muhammad Junaid

You have cloned the correct repository. I think they have not pushed into the master branch. The other branches will be there like origin/development-example. You need to make a local branch which can track the remote branches and then you can get the latest code. This is how you can track remote branches:

您已经克隆了正确的存储库。我认为他们还没有推入主分支。其他分支将在那里,如 origin/development-example。您需要创建一个可以跟踪远程分支的本地分支,然后您才能获得最新的代码。这是您可以跟踪远程分支的方法:

git branch --track dev-example origin/dev-example
git checkout dev-example

回答by Mohammed Muzammil

This happens when you are cloning a freshly created repository with no commits.

当您在没有提交的情况下克隆新创建的存储库时会发生这种情况。

As it says, it is just a warning. If it is expected that there is nothing in the repository, you can go ahead and add files and commit and push back.

正如它所说,这只是一个警告。如果预计存储库中没有任何内容,您可以继续添加文件并提交和推回。

If it is not supposed to be empty, contact the person/admin who gave you the link.

如果它不应该为空,请联系向您提供链接的人员/管理员。

回答by robsch

In my case it was a silly mistake when I've tried to clone a repo from another machine: I've used httpsinstead of sshas protocol in the URL. Surprisingly I've got no error, but the message “You appear to have cloned an empty repository”.

在我的例子中,当我试图从另一台机器克隆一个 repo 时,这是一个愚蠢的错误:我在 URL 中使用了https而不是ssh作为协议。令人惊讶的是,我没有出现错误,但出现消息“您似乎克隆了一个空存储库”。