</>
Skip to content
Git lessons (34/44)

Git — Reflog

What is Reflog?

Reflog records all changes to HEAD, allowing recovery of lost commits.

View Reflog

git reflog

Reflog Output

abc1234 HEAD@{0}: commit: Add feature
def5678 HEAD@{1}: reset: moving to HEAD~1
ghi9012 HEAD@{2}: commit: Initial commit

Recover Lost Commit

# Find lost commit hash
git reflog

# Recover it
git checkout commit-hash
git branch recover-branch

Recover Deleted Branch

# Find last commit on branch
git reflog

# Create new branch
git branch recovered-branch commit-hash

Reflog Expiration

# Default: 90 days for reachable, 30 days for unreachable
git reflog expire --expire=now --all

Mini Practice

  1. View reflog
  2. Recover a lost commit
  3. Recover a deleted branch
  4. Understand reflog entries

Up Next

Continue with Bisect — binary search for bugs.

Related Topics

Frequently Asked Questions about Reflog

What is Reflog in Git?

Reflog is a fundamental concept in Git. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Reflog?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Reflog.

Why is Reflog important in Git?

Reflog is essential for Git development. Understanding this concept will help you write better code and solve real-world problems more effectively.