0
0
Gitdevops~5 mins

Recovering from hard reset in Git - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the command git reset --hard do?
It resets the current branch to a specific commit and discards all changes in the working directory and staging area, making the repository match exactly that commit.
Click to reveal answer
beginner
How can you find the commit hash before a hard reset?
Use git reflog to see a list of recent HEAD positions, including before the hard reset.
Click to reveal answer
intermediate
Which command restores your branch to the state before a hard reset?
Use git reset --hard <commit-hash> where <commit-hash> is the commit before the reset, found via git reflog.
Click to reveal answer
beginner
What is git reflog used for?
It records updates to the tip of branches and HEAD, allowing you to find lost commits or states after operations like hard reset.
Click to reveal answer
intermediate
Why is it important to act quickly after a hard reset if you want to recover?
Because Git's reflog entries expire after some time and garbage collection may remove unreachable commits, making recovery impossible later.
Click to reveal answer
What command helps you see previous HEAD positions after a hard reset?
Agit branch
Bgit status
Cgit log --oneline
Dgit reflog
Which command will discard all local changes and reset to a specific commit?
Agit reset --soft
Bgit checkout
Cgit reset --hard
Dgit commit --amend
If you want to undo a hard reset, what is the first step?
ARun git push
BFind the previous commit hash using git reflog
CRun git merge
DDelete the .git folder
What happens if you run git reset --hard HEAD~1?
AMoves HEAD to the previous commit and discards changes
BCreates a new commit
CPushes changes to remote
DShows the commit log
Why might recovery from a hard reset fail after some time?
ABecause reflog entries expire and unreachable commits get deleted
BBecause git reset deletes the repository
CBecause commits are encrypted
DBecause git reflog is disabled by default
Explain how to recover your work after accidentally running a hard reset in Git.
Think about how Git tracks HEAD changes and how to move back.
You got /3 concepts.
    Describe the role of git reflog in recovering from destructive Git commands.
    It is like a safety log for your Git history.
    You got /3 concepts.