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

repo init克隆manifest失败 提示fatal: not in a git directory

故障现象

执行repo init拉取Android源码Manifest配置时流程中断,报错信息如下:

android@buildserver:~/aosp$ repo init -u https://android.googlesource.com/platform/manifest
Downloading Repo source from https://gerrit.googlesource.com/git-repo
repo: error: "git" failed with exit status 128
  cwd: /home/android/aosp/.repo/repo
  cmd: ['git', 'config', 'remote.origin.url', 'https://gerrit.googlesource.com/git-repo']
  stderr:
  >> fatal: not in a git directory
fatal: double check your --repo-rev setting.
fatal: cloning the git-repo repository failed, will remove '.repo/repo'

执行repo version检查工具状态,输出如下:

android@buildserver:~/aosp$ repo version
<repo not installed>
repo launcher version 2.21
       (from /usr/local/bin/repo)
git 2.25.1
Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0]
OS Linux 5.4.0-110-generic (#124-Ubuntu SMP Thu Apr 14 19:46:19 UTC 2022)
CPU x86_64 (x86_64)

注意:repo version输出的<repo not installed>不属于安装故障。repo工具分为引导启动器和核心组件两部分,首次执行init前本地仅安装了引导器,核心组件会在init阶段自动拉取到工作目录。

故障原因
  • 历史执行repo命令失败后,残留了损坏的.repo目录结构,Git识别到.repo/repo路径存在但不是合法Git仓库,无法执行配置写入操作
  • Git 2.25及以上版本新增安全目录校验规则,默认拦截不在信任列表内路径的Git操作,导致repo拉取核心组件时被Git拒绝
  • 网络连通性异常导致拉取git-repo核心仓库中途中断,残留不完整的仓库文件
解决步骤
  • 清理当前工作目录下残留的损坏缓存
rm -rf /home/android/aosp/.repo
  • 配置Git信任规则,避免安全目录拦截操作。如果不想全局放开所有路径,可将命令中的*替换为AOSP工作目录的绝对路径,即/home/android/aosp
git config --global safe.directory '*'
  • 重新执行repo init命令即可。如果官方源访问超时,可替换为网络可达的镜像源地址
repo init -u https://android.googlesource.com/platform/manifest

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.02 03:24:28