Imagine you accidentally deleted some commits in your Git repository. Why is it important to know how to recover them?
Think about what happens if you lose work you spent time on.
Lost commits may contain valuable changes. Knowing recovery helps avoid losing work and saves time.
After running git reset --hard HEAD~1, what does git reflog show?
git reset --hard HEAD~1 git reflog
Reflog records where HEAD has been recently.
Reflog keeps track of all recent HEAD changes, including resets, allowing recovery.
You accidentally deleted a branch named feature. Which sequence of commands will recover it?
Think about how to find the commit hash of the deleted branch.
Using git reflog helps find the last commit hash of the deleted branch, then git checkout -b recreates it.
You run git checkout -b fix . What error will Git show?
Think about what happens if the commit hash does not exist.
Git reports 'fatal: reference is not a tree' when the commit hash is invalid or not found.
Which practice helps prevent losing commits accidentally?
Think about how backups and isolation help protect work.
Pushing to remote and using branches isolates work and creates backups, reducing risk of loss.