"致命:不是git存储库(或任何父目录)"来自git status

Kev*_*lan 85 git clone repository git-clone git-status

此命令用于获取文件并编译它们:

git clone a-valid-git-url
Run Code Online (Sandbox Code Playgroud)

例如:

git clone git://cfdem.git.sourceforge.net/gitroot/cfdem/liggghts
Run Code Online (Sandbox Code Playgroud)

但是,git status(或任何其他git命令)然后给出上述fatal: Not a git repository (or any of the parent directories)错误.

我究竟做错了什么?

Mic*_*ant 142

你必须先实际进入目录:

$ git clone git://cfdem.git.sourceforge.net/gitroot/cfdem/liggghts
Cloning into 'liggghts'...
remote: Counting objects: 3005, done.
remote: Compressing objects: 100% (2141/2141), done.
remote: Total 3005 (delta 1052), reused 2714 (delta 827)
Receiving objects: 100% (3005/3005), 23.80 MiB | 2.22 MiB/s, done.
Resolving deltas: 100% (1052/1052), done.

$ git status
fatal: Not a git repository (or any of the parent directories): .git
$ cd liggghts/
$ git status
# On branch master
nothing to commit (working directory clean)
Run Code Online (Sandbox Code Playgroud)

  • 当 git 软管它自己的 .git 目录时,您也会收到此错误。我拉了一下,看到了“在后台自动打包存储库以获得最佳性能”的消息。然后我尝试做更多的操作,只得到 OP 的错误信息。我的 .git 文件夹仍然存在,但 git 不知何故损坏了它。运行`git init` 解决了这个问题。 (5认同)
  • 我是多么愚蠢啊。在进入目录之前尝试 git status :) 非常感谢。 (3认同)

luc*_*svc 11

就我而言,是一个环境变量GIT_DIR,我添加了更快的访问权限.

这也破坏了我在SourceTree的所有本地回购:​​(


Umi*_*aya 9

有时是因为 ssh。所以你可以使用这个:

git clone https://cfdem.git.sourceforge.net/gitroot/cfdem/liggghts
Run Code Online (Sandbox Code Playgroud)

代替:

git clone git://cfdem.git.sourceforge.net/gitroot/cfdem/liggghts
Run Code Online (Sandbox Code Playgroud)


小智 9

我刚收到这条消息,在尝试其他人之前有一个非常简单的答案.在父目录中,键入git init

这将初始化git的目录.然后git add,git commit应该工作.

  • 克隆之前还是之后?这会创建一个新的 git 存储库吗?这将如何与现有的 git 存储库和克隆的历史一起使用?在这种安排下,原来的“远程”设置会发生什么变化? (3认同)

小智 7

如果计划将现有项目解决方案转移到 VS Code 中的 TSF:

打开终端并运行以下命令:

  1. 在该文件夹(根目录)中初始化git

    git init

  2. 添加Git

    git add .

  3. 将您的 TSf/Git链接到该项目 - {url} 替换为您的 git 地址

    git remote add origin {url}

  4. 提交这些更改:

    git commit -m "initial commit"

  5. 推送- 我将代码推送为 version1,你可以为你的分支使用任何名称

    git push origin HEAD:Version1


小智 5

当我尝试使用git init初始化 git 时,此错误得到解决。有效