【问题标题】:git status "fatal: not a git repository (or any of the parent directories): .git"git status “致命:不是 git 存储库(或任何父目录):.git”
【发布时间】:2022-01-05 06:11:16
【问题描述】:

我正在与我的队友合作开展一个项目,其中我的一位队友已将我们的项目上传到 GitHub。

我想将存储库克隆到我的 VS Code 中。

以下是我执行的步骤:

  1. 我点击了队友仓库右上角的“Fork”按钮。
  2. 然后我转到“Your Repositories”并单击我刚才 fork 的存储库。
  3. 然后我单击绿色按钮“代码”并复制了我的存储库的 URL。
  4. 接下来,我转到我的 VS Code 并输入 git clone <URL>,其中的 URL 是我刚刚复制的 URL。
  5. 然后我的 VS Code 终端显示这条长消息:

Screenshot 1

  1. 然后当我运行git status 时,输出为fatal: not a git repository (or any of the parent directories): .git,如屏幕截图底部所示。

我可以知道我做错了什么吗?纠正终端显示的问题的正确步骤是什么?谢谢。

【问题讨论】:

标签: git-clone git-status


【解决方案1】:

您需要存在于克隆 git 存储库的活动目录中。

cd 到下载的目录,然后 VS Code 将自动使用当前的 repo 进行更新。

尝试使用 Git lens 等扩展和其他与 git 相关的扩展,以简化此过程。

【讨论】:

  • 我可以知道如何执行cd into the downloaded directory吗?
  • 在命令行/Powershell终端输入cd <your-directory-name>。在您的情况下,它应该是 cd student-course-registration-system 。另一个注意事项:当我仔细查看您的屏幕截图时,您的 git checkout 过程似乎失败了。可能是网络错误或存储库未正确维护。再次尝试 git 克隆,然后使用 cd 更改活动目录,如上所示。
  • 我尝试运行cd student-course-registration-system,当我再次运行git status 时,我的终端显示以下结果:Screenshot。我可以知道如何解决这个问题吗?
【解决方案2】:

我已经尝试运行 cd student-course-registration-system,当我再次运行 git status 时,我的终端显示以下结果:

如截图所述,使用git restore

git restore --staged --worktree -- .

这会将 HEAd 提交中的所有文件恢复到您的工作树和索引。

【讨论】:

    猜你喜欢
    • 2012-08-11
    • 1970-01-01
    • 1970-01-01
    • 2013-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 2012-09-03
    相关资源
    最近更新 更多