git runtime_error ai_generated true

致命错误:此操作必须在工作树中运行

fatal: This operation must be run in a work tree

ID: git/detached-head-from-bare-repo

其他格式: JSON · Markdown 中文 · English
90%修复率
85%置信度
1证据数
2024-02-15首次发现

版本兼容性

版本状态引入弃用备注
git 2.43.0 active
git 2.44.0 active
git 2.45.0 active

根因分析

尝试在裸仓库中运行需要工作树的命令(如checkout或status)

English

Attempting to run a command that requires a working tree (like checkout or status) inside a bare repository.

generic

官方文档

https://git-scm.com/docs/git-worktree

解决方案

  1. Clone the bare repo into a working tree: git clone /path/to/bare.git /tmp/workdir && cd /tmp/workdir && git status
  2. Use 'git worktree add' to create a linked working tree from the bare repo: git worktree add /tmp/workdir main

无效尝试

常见但无效的做法:

  1. Running 'git checkout main' in a bare repo thinking it will switch branches 95% 失败

    Bare repos have no working tree; checkout cannot modify files

  2. Setting GIT_DIR to a bare repo path and running git status 90% 失败

    Bare repos store only objects, no index or working tree for status