# 错误：运行维护失败：无法创建临时文件：权限被拒绝

- **ID:** `git/error-failed-to-run-maintenance`
- **领域:** git
- **类别:** system_error
- **错误码:** `EACCES`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

Git 的后台维护任务（如 gc 或 commit-graph write）无法在仓库的对象目录中创建临时文件，原因是文件系统权限不足或磁盘空间不足。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| git 2.31.0 | active | — | — |
| git 2.40.0 | active | — | — |
| git 2.44.0 | active | — | — |

## 解决方案

1. ```
   chmod -R u+w .git/objects  # Grant write permission to the objects directory for the current user
   ```
2. ```
   df -h && du -sh .git  # Check disk space; if full, free up space by removing large files or running git maintenance stop to disable auto-maintenance
   ```

## 无效尝试

- **** — Running git gc manually without addressing permission issues will fail with the same error because gc also needs to create temp files. (95% 失败率)
- **** — Changing ownership of .git/objects to root with chown -R root:root can break other git operations and is not a proper fix. (80% 失败率)
