fatal: 不 git 仓库
错误信息
fatal: 不 git 仓库 (or 任何的 parent directories): .git
快速摘要
你 ran git command in directory 那个 isn't 内部 git 仓库 — 那里's 否 `.git` folder in 这个 or 任何 parent directory.
为什么发生
你're 不内部 git 仓库 —
git init是从不运行这里.gitfolder 是删除 or corrupted你're in 错误 terminal directory
最小示例
✗ 错误代码
cd /tmp
git status # fatal: not a git repository✓ 修复代码
cd /tmp/my-project
git status # works — inside a repo运行 git 状态 in /tmp 失败因为它's 不 git 仓库 — CD 到项目 directory 那个有 .git folder 首先.
如何诊断
运行
git 状态— 如果它失败, 你're 不 in 仓库检查 for
.gitfolder 使用ls -验证你的 current directory 使用
pwd— 是你 in 项目 folder?
如何修复
运行
git init到创建新仓库 in 这个 directory更改 directory (
CD) 到正确项目 folder克隆仓库再次如果
.gitfolder 是 missing
如何预防
总是运行
git 状态首先到确认你're in 仓库Use terminal prompts 那个 show git 分支到 avoid confusion