# Git 如何找回丢失 commit

URL: https://caijiao.org/how-to/git/recover-lost-commit
Source: docs/how-to/git/recover-lost-commit.md
Description: Git 如何找回丢失 commit：先用 git reflog 找到 HEAD 历史位置，再创建恢复分支或 reset 回目标提交。

## 快速答案

先查看 reflog：

```bash
git reflog
```

找到目标提交后，建议先创建恢复分支：

```bash
git switch -c recover-work <commit>
```

如果确认要把当前分支回到该提交：

```bash
git reset --hard <commit>
```

## 推荐流程

1. 先 `git status`，确认当前工作区是否干净。
2. 用 `git reflog` 找到 reset、rebase、checkout 前的位置。
3. 用 `git switch -c recover-work <commit>` 建分支，避免继续破坏现场。
4. 确认内容正确后，再决定 merge、cherry-pick 或 reset。

## 常见坑

- 直接 reset 到 reflog 位置，覆盖当前工作区未保存改动。
- 以为 reflog 是永久记录；过期清理后可能无法恢复。
- 只看 `git log`，看不到已经不在当前分支历史上的提交。

## 相关内容

- [Git 常见问题](/how-to/git/)
- [git reflog 参考](/reference/git/reflog)
- [git reset 参考](/reference/git/reset)
- [Git 教程：撤销与恢复](/git/history/undo)
