Reflog records local reference movement and can help find commits no longer named by a branch. It is local and subject to expiration.
Before you start
You should understand commits, branches, the working tree and the staging area. Draw the commit graph before changing history. Try commands in a disposable repository with a clean working tree so you can observe exactly which references and files each operation changes.
The practical goal is to reason through this situation: A branch reset may leave its old tip discoverable in that repository’s reflog. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.
Step-by-step walkthrough
Step 1: Find prior reference movement
Inspect the local reflog for the accidentally replaced tip.
Step 2: Create a recovery reference
Name the candidate commit before making additional history changes.
Step 3: Verify contents
Confirm the desired files and commits are actually present.
Worked scenario
A branch reset may leave its old tip discoverable in that repository’s reflog.
A branch reset no longer names its earlier commits. The local reflog may still record its previous tip, allowing a recovery branch to preserve that commit. Entries expire and are local to that repository, so this is a recovery aid rather than a permanent remote backup.
Common mistake
Reflog is not a permanent backup or shared remote history.
Verify the behavior
Recover in a disposable repository and compare the restored tree with the intended state.
Interview exercise
Recover an accidentally moved branch.
Answer and reasoning
Identify the correct commit, create a recovery reference and inspect its contents before changing other branches.
Continue learning
Compare the scenario with the Git and CI/CD interview questions and test your understanding with the Git and CI/CD MCQs. For terminology and implementation details, consult the reference material.