来自git status的错误信息:"fatal: Not a git repository (or any of the parent directories)"。

134

这个命令用来获取文件并编译它们:

git clone a-valid-git-url
例如:
git clone git://cfdem.git.sourceforge.net/gitroot/cfdem/liggghts

然而,git status(或任何其他git命令)随后会出现上述的fatal: Not a git repository (or any of the parent directories)错误。

我做错了什么?


6
检出的代码位于 liggghts 目录中。 - Eugen Constantin Dinca
15个回答

1

简单来说,当你克隆完仓库后,你需要cd(更改当前目录)到新克隆的文件夹中。

git clone https://User_Name@bitbucket.org/Repo_Name.git

cd Repo_Name

1
对我来说,我一直在使用Visual Studio时遇到了清理解决方案的问题,所以我使用通配符删除了所有名为bin、obj的目录... .git目录中有一个名为/objects的目录也被误删了。 我是在对比工作中的克隆版本和出错的版本时发现的。 糟糕 :)

0

我突然在任何目录中运行git命令时都遇到了以下错误:

fatal: Not a git repository: /Users/me/Desktop/../../.git/modules/some-submodule

后来发现我的桌面上有一个名为.git的隐藏文件,其内容如下:

gitdir: ../../.git/modules/some-module

删除该文件即可解决问题。


0
我在办公室网络中遇到了同样的问题。 我使用了这个命令,但对我来说没有用: url, 就像这样: 之前 $ git clone https://gitlab.com/omsharma/Resume.git

之后我使用了这个URL:$ git clone https://my_gitlab_user@gitlab.com/omsharma/Resume.git 试试吧。


0
在我的情况下,我正在处理 Github 工作流程任务,只是在我的步骤之前忘记了检出仓库。添加先决步骤 actions/checkout@v2 解决了这个问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接