recovery
git reflog
Shows the log of updates to branch tips and HEAD stored locally, even after commits are dropped from history. The rescue rope for recovering 'lost' commits.
git reflog [<subcommand>] [<options>] [<ref>] Common flags
| Flag | Purpose |
|---|---|
| show <ref> | Display reflog entries for a specific ref |
| expire | Prune old reflog entries |
| delete <entry> | Remove specific reflog entries |
| --date=iso | Show timestamps in ISO format |
| --all | Show reflogs for every ref |
Examples
git reflog See recent HEAD movements — great after a bad reset
git reset --hard HEAD@{2} Jump HEAD back to state 2 moves ago
git reflog show main History of updates to the main branch tip
Gotcha
Reflog is local-only and expires after 90 days by default; recover lost commits promptly before garbage collection removes them.
Related commands
git reset
Moves the current branch tip to a specified commit, optionally updating the index and working tree. Used to unstage files or rewind local history.
git log
Displays commit history in reverse chronological order with filters for author, date, path, or content. The primary tool for exploring project history.
git revert
Creates a new commit that inverts the changes of a previous commit, preserving history. The safe way to undo pushed commits on shared branches.
git restore
Modern command (Git 2.23+) for restoring working tree files from the index or a commit, or unstaging files. Replaces the confusing file-mode of 'git checkout'.
git stash
Shelves uncommitted changes onto a stack so you can switch context with a clean working tree. Later, reapply them with pop or apply.