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.
Git & GitHub
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.
0 of 8 lessons done · proved by a submitted project with a public repository
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
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.jsxMaybe 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 statusBeginners 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 statusIf 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>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 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
Answer the quick check to finish this lesson.