Pause before fixing
Most Git trouble gets worse when you copy random commands. First inspect what changed, what is staged, and where HEAD points.
Your safe order is: git status, git diff, git log --oneline. Then choose the smallest fix.
Check the damage
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 5 done
Undo file edits
Use this when you edited a file and want to throw away only those unstaged changes. This cannot be undone from Git, so read the diff first.
git diff src/App.jsx
git restore src/App.jsxUnstage wrong files
Maybe you ran git add . and included .env, screenshots, or half-written code. Unstage them. This keeps the file changes on your laptop.
git status
git restore --staged .env
git restore --staged src/rough-notes.js
git statusReset is not magic
Beginners use git reset --hard because Stack Overflow said so. It deletes tracked local changes in your working tree.
Use it only when you are sure you want to throw away local edits. For a college project repo, first make a backup branch if you are unsure.
git branch backup-before-fix
git statusFix a bad commit
If the bad commit is only on your laptop, you can move back one commit and keep the file changes. Then recommit properly.
If the commit is already pushed and teammates may have pulled it, prefer git revert. Revert creates a new commit that undoes the old one.
# Local commit, not pushed yet
git reset --soft HEAD~1
git status
# Pushed commit, safer for shared history
git log --oneline
git revert <commit-hash>Use reflog rescue
Reflog records where your HEAD and branches recently pointed. It helps when you reset, checkout, or rebase to the wrong place.
Find the commit you want, then create a branch there. A new branch is safer than moving your current branch again.
git reflog
git branch rescue <commit-hash>
git switch rescueDo this now
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 5 done