# 错误：补丁失败：file.txt:1
错误：file.txt: 补丁无法应用

- **ID:** `git/am-failed-patch`
- **领域:** git
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

补丁文件（来自git format-patch或邮件）无法应用，因为目标文件与补丁的基础版本存在差异

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| git 2.41.0 | active | — | — |
| git 2.42.0 | active | — | — |
| git 2.43.0 | active | — | — |

## 解决方案

1. ```
   Apply the patch with 'git apply --reject' to see which hunks fail, then manually fix: git apply --reject patch.diff && vim file.txt
   ```
2. ```
   Use 'git am --3way --ignore-whitespace' to apply with more tolerance: git am --3way --ignore-whitespace patch.mbox
   ```

## 无效尝试

- **Using 'git am --3way' without checking for conflicts first** — 3-way merge may still fail if the patch context is too old (70% 失败率)
- **Manually editing the patch file to change line numbers** — Patch context (surrounding lines) must match exactly; changing line numbers alone doesn't fix context mismatches (90% 失败率)
