0
0
Gitdevops~20 mins

Recovering lost commits with reflog in Git - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Reflog Recovery Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of git reflog after a commit reset?
You ran git reset --hard HEAD~1 to undo the last commit. What will git reflog show as the latest entry?
Git
git reset --hard HEAD~1
git reflog
AHEAD@{0}: merge: moving to HEAD~1
BHEAD@{0}: commit: Undo last commit
CHEAD@{0}: checkout: moving to HEAD~1
DHEAD@{0}: reset: moving to HEAD~1
Attempts:
2 left
💡 Hint
Think about what git reset --hard does to the HEAD pointer.
🧠 Conceptual
intermediate
2:00remaining
Which command recovers a lost commit using reflog?
You accidentally lost a commit after a reset. Which command correctly restores the lost commit using reflog?
Agit revert HEAD@{1}
Bgit checkout HEAD@{1}
Cgit reset --hard HEAD@{1}
Dgit merge HEAD@{1}
Attempts:
2 left
💡 Hint
You want to move HEAD back to the lost commit forcibly.
Troubleshoot
advanced
2:00remaining
Why does git reset HEAD@{2} fail to restore a lost commit?
You tried git reset HEAD@{2} to recover a lost commit but it did not work as expected. What is the most likely reason?
AHEAD@{2} is not a valid reflog entry
BIt does not use the <code>--hard</code> flag, so working directory and index are not updated
CYou need to use <code>git revert</code> instead of reset
DThe reflog only tracks branches, not commits
Attempts:
2 left
💡 Hint
Consider what git reset does by default without flags.
🔀 Workflow
advanced
3:00remaining
Order the steps to recover a lost commit using reflog
Arrange the steps in the correct order to recover a lost commit using reflog.
A1,2,3,4
B2,1,3,4
C3,1,2,4
D1,3,2,4
Attempts:
2 left
💡 Hint
Think about finding the commit first, then restoring it, then verifying.
Best Practice
expert
3:00remaining
What is the safest way to recover a lost commit without risking current work?
You want to recover a lost commit using reflog but keep your current changes safe. Which approach is best?
ACreate a new branch at the lost commit using 'git branch recover HEAD@{1}'
BRun 'git reset --hard HEAD@{1}' directly to restore the commit
CUse 'git checkout HEAD@{1}' to switch to the lost commit detached HEAD
DRun 'git revert HEAD@{1}' to undo changes
Attempts:
2 left
💡 Hint
Think about preserving your current work and avoiding forced resets.