You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git仓库突发“fatal: not a git repository”错误求助

解决Git Status报错:fatal: not a git repository

执行git status时触发报错:

fatal: not a git repository: xx/static/vendor/bootstrap/../../../../.git/modules/xx/static/vendor/bootstrap

当前所在目录并非报错中指向的路径,本地.git文件夹包含以下内容:

FETCH_HEAD
HEAD
ORIG_HEAD
branches
config
description
hooks
index
info
logs
objects
packed-refs
refs

已尝试Stack Overflow上的两个方案但无效:

  • 《How to "resolve fatal: Not a git repository"?》:环境中无方案提及的modules文件夹
  • 《getting error message "fatal: Not a git repository" on entering command "git remote -v"》:方案无效果

解决步骤

1. 删除配置文件中的无效子模块记录

打开.git/config文件,搜索包含[submodule]或者xx/static/vendor/bootstrap的配置段落,直接删除这些无效条目,保存后再运行git status测试。

2. 清理索引中的无效路径

执行以下命令,移除Git索引里残留的无效子模块引用:

git rm --cached xx/static/vendor/bootstrap

完成后再次执行git status,查看是否恢复正常。

3. 重置仓库并清理冗余数据

如果前两步无效,可尝试重置仓库状态并清理Git的冗余数据:

git reset --hard HEAD
git gc --prune=now

⚠️ 注意:git reset --hard会丢弃工作区所有未提交的修改,执行前务必备份重要内容。

4. 检查目标目录的.git文件

前往xx/static/vendor/bootstrap目录,查看是否存在名为.git的文件(不是文件夹),如果有,直接删除该文件即可。

内容的提问来源于stack exchange,提问作者Kiwiheretic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 07:28:17