Git clone: “You appear to have cloned an empty repository”

匿名 (未验证) 提交于 2019-12-03 00:50:01

问题:

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:

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

A git log provides:

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

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.

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:

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

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

If for some reason gitlab-git-http-server is 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.

A quick fix is to use git over ssh to clone the repo.



回答2:

You have clonned the correct repository. I think they have not pushed in master branch. The other branches will be there like origin/developemnt-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:

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


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!