# error: patch failed: file.txt:1
error: file.txt: patch does not apply

- **ID:** `git/am-failed-patch`
- **Domain:** git
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A patch file (from git format-patch or email) cannot be applied because the target file has diverged from the patch's base.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| git 2.41.0 | active | — | — |
| git 2.42.0 | active | — | — |
| git 2.43.0 | active | — | — |

## Workarounds

1. **Apply the patch with 'git apply --reject' to see which hunks fail, then manually fix: git apply --reject patch.diff && vim file.txt** (85% success)
   ```
   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** (75% success)
   ```
   Use 'git am --3way --ignore-whitespace' to apply with more tolerance: git am --3way --ignore-whitespace patch.mbox
   ```

## Dead Ends

- **Using 'git am --3way' without checking for conflicts first** — 3-way merge may still fail if the patch context is too old (70% fail)
- **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% fail)
