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

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

"fatal: Not a git repository (or any of the parent directories)" from git status

gitrepositoryclonegit-clonegit-status

提问by Kevin Kostlan

This command works to get the files and compile them:

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

git clone a-valid-git-url

for example:

例如:

git clone git://cfdem.git.sourceforge.net/gitroot/cfdem/liggghts

However, git status(or any other git command) then gives the above fatal: Not a git repository (or any of the parent directories)error.

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

What am I doing wrong?

我究竟做错了什么?

回答by Michael Durrant

You have to actually cd into the directory first:

您必须首先实际 cd 进入目录:

$ 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)

回答by Bill

I just got this message and there is a very simple answer before trying the others. At the parent directory, type git init

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

This will initialize the directory for git. Then git addand git commitshould work.

这将初始化 git 的目录。然后git addgit commit应该工作。

回答by lucasvc

In my case, was an environment variable GIT_DIR, which I added to access faster.

就我而言,是一个环境变量GIT_DIR,我添加了它以更快地访问。

This also broke all my local repos in SourceTree :(

这也破坏了我在 SourceTree 中的所有本地存储库:(

回答by keyo

in my case, i had the same problem while i try any git -- commands (eg git status) using windows cmd. so what i do is after installing git for window https://windows.github.com/in the environmental variables, add the class path of the git on the "PATH" varaiable. usually the git will installed on C:/user/"username"/appdata/local/git/binadd this on the PATH in the environmental variable

就我而言,当我使用 Windows cmd 尝试任何 git -- 命令(例如 git status)时,我遇到了同样的问题。所以我要做的是在 环境变量中为窗口https://windows.github.com/安装 git 后,在“PATH”变量中添加 git 的类路径。通常 git 将安装在C:/user/"username"/appdata/local/git/bin环境变量的 PATH 中

and one more thing on the cmd go to your git repository or cd to where your clone are on your window usually they will be stored on the documents under github

cmd 上的另一件事转到您的 git 存储库或 cd 到您的克隆在您的窗口中的位置通常它们将存储在 github 下的文档中

cd Document/Github/yourproject

after that you can have any git commands

之后你可以有任何git命令

回答by Frank Conry

I had another problem. I was in a git directory, but got there through a symlink. I had to go into the directory directly (i.e. not through the symlink) then it worked fine.

我还有一个问题。我在 git 目录中,但通过符号链接到达那里。我必须直接进入目录(即不是通过符号链接)然后它工作正常。

回答by Umit Kaya

Sometimes its because of ssh. So you can use this:

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

git clone https://cfdem.git.sourceforge.net/gitroot/cfdem/liggghts

instead of:

代替:

git clone git://cfdem.git.sourceforge.net/gitroot/cfdem/liggghts

回答by Roopal

This error got resolved when I tried initialising the git using git init. It worked

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

回答by Madlozoz

In my case, the original repository was a bare one.

就我而言,原始存储库是一个裸存储库。

So, I had to type (in windows):

所以,我不得不输入(在 Windows 中):

mkdir   dest
cd dest
git init
git remote add origin a\valid\yet\bare\repository
git pull origin master

To check if a repository is a bare one:

要检查存储库是否是裸存储库:

git rev-parse --is-bare-repository 

回答by Onengiye Richard

git clone https://github.com/klevamane/projone.git
Cloning into 'projone'...
remote: Counting objects: 81, done.
remote: Compressing objects: 100% (66/66), done.
remote: Total 81 (delta 13), reused 78 (delta 13), pack-reused 0
Unpacking objects: 100% (81/81), done.

you have to "cd projone"

你必须“CD projone”

then you can check status.

然后你可以检查状态。



One reason why this was difficult to notice at first, i because you created a folder with the same name already in your computer and that was where you cloned the project into, so you have to change directory again

一开始很难注意到这一点的一个原因,我是因为您已经在您的计算机中创建了一个同名文件夹,这是您将项目克隆到的位置,因此您必须再次更改目录



回答by Abdallah Okasha

Simply, after you clone the repo you need to cd (change your current directory)to the new cloned folder

简单地说,克隆存储库后,您需要 cd (更改当前目录)到新的克隆文件夹

git clone https://[email protected]/Repo_Name.git

cd Repo_Name