# 致命：<提交哈希> 不是 HEAD 的祖先

- **ID:** `git/commit-not-ancestor-rebase`
- **领域:** git
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

尝试变基到一个从当前分支历史无法到达的提交，违反了变基的前提条件，即上游提交必须是祖先。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| git 2.40.0 | active | — | — |
| git 2.41.1 | active | — | — |
| git 2.42.0 | active | — | — |

## 解决方案

1. ```
   Use 'git log --oneline --graph' to inspect the commit graph and ensure the target commit is reachable, then rebase onto a correct ancestor like 'git rebase --onto <target> <old-base>'
   ```
2. ```
   If the commit is in another branch, merge that branch first with 'git merge <other-branch>' to make the commit an ancestor, then rebase
   ```

## 无效尝试

- **** — The --onto option expects a valid upstream; using an unrelated commit still fails the ancestor check or creates a broken history. (70% 失败率)
- **** — Fetching updates remote refs but does not change the local branch's ancestry; the error persists unless the branch is reset or merged. (55% 失败率)
