# 冲突（修改/删除）：file.txt 在 HEAD 中被删除，但在分支中被修改。分支版本的 file.txt 保留在树中。

- **ID:** `git/conflict-modify-delete`
- **领域:** git
- **类别:** conflict_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

合并的一方删除了一个文件，而另一方修改了该文件，导致修改/删除冲突。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| git 2.30.0 | active | — | — |
| git 2.39.0 | active | — | — |
| git 2.45.0 | active | — | — |

## 解决方案

1. ```
   git checkout --ours file.txt && git add file.txt  # Keep the deleted side (HEAD), effectively deleting the file
   ```
2. ```
   git checkout --theirs file.txt && git add file.txt  # Keep the modified side (branch), restoring the file with modifications
   ```

## 无效尝试

- **** — Running git add on the conflicted file without resolving the conflict will keep the conflict marker in the staged file, leading to build errors or incorrect content. (65% 失败率)
- **** — Using git merge --abort when you actually want to keep changes discards all merge progress and requires starting over. (30% 失败率)
