Lazo Lab Sign up

Git, AI Tools & Your Career / Git and GitHub

Lesson 11 of 32

Undoing changes

git restore throws away uncommitted edits to a file, and git revert makes a new commit that undoes an old one. Revert is safe on shared branches because it doesn't rewrite history.

Key points

  • git restore file: drop local edits
  • git revert <commit>: undo safely
  • Avoid rewriting shared history
git restore app.py
git revert a1b2c3d
Watch a video on thisOpens YouTube search results for “Undoing changes” in a new tab

Quiz · +10 XP

Which command safely undoes a commit that's already been pushed?

Log in to save progress and earn XP.