# 错误：以下未跟踪的工作树文件将被检出覆盖：file.txt

- **ID:** `git/checkout-conflict-with-untracked-files`
- **领域:** git
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

Git检出会覆盖工作目录中未跟踪的文件，这些文件在目标分支中存在，但在当前分支中未被跟踪。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2.38.0 | active | — | — |
| 2.39.0 | active | — | — |
| 2.40.0 | active | — | — |

## 解决方案

1. ```
   将冲突的未跟踪文件移动到安全位置：'mv file.txt file.txt.backup'。然后检出分支。检出后，如果需要可以比较并恢复。
   ```
2. ```
   或者，将未跟踪文件暂存：'git stash --include-untracked'。然后检出分支。之后应用暂存：'git stash pop'。
   ```

## 无效尝试

- **Adding the file to .gitignore and retrying checkout.** — The file is already untracked, so .gitignore won't help; it only prevents future tracking. The checkout still sees the file as a conflict. (90% 失败率)
- **Using 'git checkout --force' to override the error.** — Force checkout will overwrite the untracked file, potentially losing data. It works but is dangerous. (30% 失败率)
- **Running 'git clean -fd' to delete all untracked files blindly.** — This deletes all untracked files, not just the conflicting one, which may remove important files. (50% 失败率)
