Reverting changes in Git traditionally required using git checkout
to restore files or git reset
to adjust the branch HEAD. However, both commands carried risks if misused: git reset
could shift the branch HEAD, while git checkout
could either switch branches or load a different commit, potentially disrupting the current branch state.
git restore main.js
git restore --staged main.js