← Git & GitHub learning path
Git & GitHub · Module 7 of 10

Undoing changes

Fix mistakes safely with Git.

📖 Key ideas

  1. git restore file discards uncommitted changes.
  2. git restore --staged file unstages.
  3. git commit --amend fixes the last commit (before pushing).
  4. git revert commit creates a new commit undoing changes (safe for shared history).
  5. git reset moves branches back (careful with shared work).
💡 Real-life example: git revert is writing a correction note; git reset is tearing out pages (dangerous if others have copies).
git restoreDiscards or unstages changes
git revertNew commit that undoes a commit
git resetMoves branch pointer back
--amendModify the last commit