git
runtime_error
ai_generated
true
致命错误:此操作必须在工作树中运行
fatal: This operation must be run in a work tree
ID: git/detached-head-from-bare-repo
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.
官方文档
https://git-scm.com/docs/git-worktree解决方案
-
Clone the bare repo into a working tree: git clone /path/to/bare.git /tmp/workdir && cd /tmp/workdir && git status
-
Use 'git worktree add' to create a linked working tree from the bare repo: git worktree add /tmp/workdir main
无效尝试
常见但无效的做法:
-
Running 'git checkout main' in a bare repo thinking it will switch branches
95% 失败
Bare repos have no working tree; checkout cannot modify files
-
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