# Recovering Work with reflog — Git Fundamentals: Commits, Branches and Collaboration

Source: https://www.geekswithgeeks.com/en/git/git-reflog

> Find and restore commits you thought were lost after a reset, rebase or deleted branch using git reflog.

## The safety net

`git reflog` records every place `HEAD` has pointed, even after `reset --hard`, a bad rebase or a deleted branch. Commits stay recoverable for weeks until garbage collection.

## Restore a lost commit

Find the commit in the reflog, then point a branch at it.

```bash
git reflog
# a1b2c3d HEAD@{2}: commit: Add search feature
git switch -c rescued a1b2c3d     # new branch at the lost commit
# or
git reset --hard a1b2c3d
```

The reflog is local only and never pushed. If you are about to run something risky, note the current commit hash first.

Quick check

**Quiz:** Which command lists where HEAD has been, so you can recover lost commits?

- [x] git reflog
- [ ] git log --stat
- [ ] git blame
- [ ] git remote -v

*Answer:* git reflog. The reflog tracks HEAD movements, even after resets.
