What is git reflog and how can it help?

The reflog records every move of HEAD and branch tips in your local repository. Even if a commit is not in any branch anymore, you can find it there.

Terminal output

$ git reflog
0057196 (HEAD -> main) HEAD@{0}: reset: moving to HEAD~1
f411fbd HEAD@{1}: commit: Second
0057196 (HEAD -> main) HEAD@{2}: commit (initial): First
$ git reset –hard HEAD@{1}
HEAD is now at f411fbd Second
$ git log –oneline
f411fbd (HEAD -> main) Second
0057196 First

The reflog is local only, and entries expire after some time (90 days by default). See Git Reflog.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.