Git & GitHub Interview Question #57
What is git reflog?
Undo & Recovery, Tags, Forks, Pull Requests & Code Review Mid-Level Intermediate
Quick Interview Answer
git reflog records updates to local references such as HEAD and branch tips. It can help locate commits that appear to have been lost after operations such as reset, rebase, branch deletion, or checkout.
Detailed Explanation
git reflog records updates to local references such as HEAD and branch tips. It can help locate commits that appear to have been lost after operations such as reset, rebase, branch deletion, or checkout.
Reflog is local repository information and is not a substitute for a remote backup. Entries also expire according to Git's retention and cleanup behavior.
Code Example
git reflog
# Inspect a recovered commit
git show <commit-id>
# Create a branch to preserve it
git branch recovered-work <commit-id>