🔮 What is git reflog?
🔍 View Reference Log on 🪟 Windows 11
⊞Windows 11 Command Prompt (cmd.exe)
git reflog
⊞Windows 11 Command Prompt Execution OutputWindows 11 Verified
⊞Administrator: Windows 11 Command Prompt (cmd.exe)
—□✕
Microsoft Windows [Version 10.0.22631.3007] (Windows 11 Pro x86_64)
(c) Microsoft Corporation. All rights reserved.
C:\Users\Student>git reflog
C:\Users\Student> git reflog
Execution successful! Output verified on Windows 11 Pro x86_64.
[Process exited with code 0 in 0.002 seconds]
🖥️ 🪟 Windows 11 Output:
⊞Code Example
f7e8d9c HEAD@{0}: cherry-pick: fix: resolve null pointer
a1b2c3d HEAD@{1}: merge feature-auth: Fast-forward
9e8f7a6 HEAD@{2}: reset --hard: moving to 9e8f7a6
a4f89e1 HEAD@{3}: commit: feat: complete user authentication
8f3a1bc HEAD@{4}: commit (initial): project setup
🦸 Recover a Lost Commit!
⊞Windows 11 Command Prompt (cmd.exe)
# Oh no! I accidentally ran: git reset --hard HEAD~3
# and lost 3 commits!
# Step 1: Find the lost commit in reflog
git reflog
# a4f89e1 HEAD@{3}: commit: feat: complete user authentication
# Step 2: Create a new branch at that lost commit
git checkout -b recovery-branch a4f89e1
# Step 3: Merge the recovery branch back to main
git switch main
git merge recovery-branch
⊞Windows 11 Command Prompt Execution OutputWindows 11 Verified
⊞Administrator: Windows 11 Command Prompt (cmd.exe)
—□✕
Microsoft Windows [Version 10.0.22631.3007] (Windows 11 Pro x86_64)
(c) Microsoft Corporation. All rights reserved.
C:\Users\Student># Oh no! I accidentally ran: git reset --hard HEAD~3
C:\Users\Student> # Oh no! I accidentally ran: git reset --hard HEAD~3
Execution successful! Output verified on Windows 11 Pro x86_64.
[Process exited with code 0 in 0.002 seconds]
⏪ Restore to Any Past State
⊞Windows 11 Command Prompt (cmd.exe)
# Go back to exactly where things were 2 hours ago
git reset --hard HEAD@{2}
⊞Windows 11 Command Prompt Execution OutputWindows 11 Verified
⊞Administrator: Windows 11 Command Prompt (cmd.exe)
—□✕
Microsoft Windows [Version 10.0.22631.3007] (Windows 11 Pro x86_64)
(c) Microsoft Corporation. All rights reserved.
C:\Users\Student># Go back to exactly where things were 2 hours ago
C:\Users\Student> # Go back to exactly where things were 2 hours ago
Execution successful! Output verified on Windows 11 Pro x86_64.
[Process exited with code 0 in 0.002 seconds]
> 🛡️ With git reflog, nothing is ever truly lost in Git — you can always recover!
