Skip to main content

What is reflog and why is it needed?

git reflog is a log of the movements of the HEAD pointer and branches in the local repository.

It stores information about:

  • where HEAD pointed
  • which commands changed the repository's state
  • which commits were current before

Why reflog is needed

reflog lets you:

  • recover commits after a reset
  • find lost commits after a rebase
  • return to the state before a mistaken command
  • recover work after a checkout or commit --amend

Its main purpose:

reflog is an "insurance policy" against losing history in the local repository.


What is important to know

  • reflog is local - it is not transferred via push
  • it is kept for a limited time (by default ~90 days)
  • it contains even commits that are no longer reachable via git log

Example usage

bash
git reflog

The output shows the list of HEAD states:

text
HEAD@{0} reset: moving to HEAD~1 HEAD@{1} commit: add feature

You can return to a state:

bash
git checkout HEAD@{1}

or

bash
git reset --hard HEAD@{1}

A key phrasing for an interview

git reflog is a local log of HEAD changes that lets you recover commits and the repository's state after reset, rebase, and other dangerous operations.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.