What is git reflog?
Why Interviewers Ask This
Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.
Answer
git reflog shows a log of all places HEAD has pointed in the local repo — every commit, checkout, reset, merge, and rebase, with a timestamp. It's Git's safety net: even if you lose commits with git reset --hard, git rebase, or branch deletion, reflog lets you recover them as long as the 90-day retention hasn't expired. Usage: git reflog — shows recent HEAD movements with relative refs (HEAD@{0}, HEAD@{1}...); git reflog show main — reflog for a specific branch; git reflog --date=iso — show actual timestamps. Recovery scenarios: (1) Undo a bad reset: git reset --hard HEAD@{3} — go back to where you were 3 moves ago; (2) Recover deleted branch: find the last commit hash in reflog, then git checkout -b recovered-branch abc1234; (3) Undo a rebase gone wrong: find the pre-rebase HEAD in reflog, reset to it. Reflog is local only — it is NOT synced to the remote. Every entry has a hash — you can checkout, cherry-pick, or create a branch from any reflog entry. Reflog entries expire after 90 days (configurable).
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.
Previous
What is interactive rebase and how is it used for cleaning up commits?
Next
What is git submodule?