Stage 2 · Lesson 7 of 9
Undoing mistakes safely
can undo almost any mistake if you know which command fits. git restore throws away changes to a file you have not committed yet. git commit --amend fixes your last commit, as long as you have not pushed it.
git revert makes a new commit that undoes an old one. It is the safe choice for anything already pushed, because it adds to the shared history instead of rewriting it. git reset moves your branch back to an earlier commit and can throw work away, so use it only on commits nobody else has.
If you think you lost a commit, the (git reflog) lists everywhere your branch has been.
Common trapdeleting the folder and cloning again, which loses any work you had not pushed.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- GitHub repoFreeGitHub Skills: Introduction to GitHub
GitHub · Beginner
Free hands-on exercise: branch, commit, open and merge a pull request in about an hour
- CourseFreeThe Missing Semester of Your CS Education
MIT · Beginner
MIT lectures on the tools degrees skip; the shell and version control lectures are enough here
Practise
Keep handy
Also worth your time
How to choose, structure and present projects so a reviewer sees your best work first