Git Bash "Not a git repository" 错误

5

我在Windows桌面上克隆了我的一个项目,在编辑后,当我输入 git add . 命令时,会出现以下错误:

fatal: Not a git repository (or any of the parent directories): .git

如何解决?


你是怎么克隆这个项目的?你确定你也复制了.git目录(通常是隐藏的)吗? - Just Shadow
1个回答

1

当您输入git clone时,它将在当前目录下创建一个子目录。例如,如果您当前的工作目录是/code,则命令行输出可能类似于以下内容:

$ pwd
/home/you/code [or something similar]
$ ls -F
foo  bar
$ git clone http://somewhere.baz/somerepo.git
[happy git output]
$ ls -F
foo  bar  somerepo/

正如您所看到的,您的存储库已克隆到somerepo子目录中,因此完整路径类似于〜/code/repo_name。但是,您当前的工作目录保持不变,〜/code

接下来,您应该进入该目录:

$ cd somerepo
$ ls
[content of your repo]

改变当前工作目录后,您应该能够看到其内容(ls命令的输出),并使用git status命令查看git存储库状态。

我认为克隆存储库并不总是有帮助的,尤其是在进行了本地修改之后。 - Kiwiheretic

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