Interview Prep/Git & GitHub/Undoing changes: reset, revert, restore and reflog

How do you discard changes in one file?

BeginnerConceptUndoing changes: reset, revert, restore and reflog
Answer

Restore it from the index or a commit. This permanently discards the uncommitted edits since they were never stored.

git restore app.py
git restore --staged app.py              # unstage only
git restore --source=origin/main app.py  # take main's version
All Git & GitHub questions Roadmap: Git & GitHub

More on Undoing changes: reset, revert, restore and reflog