undo changes in git
Throw away changes not committed yet, unstage files, or put work aside for later.
danger Steps marked in red delete, overwrite or stop something. Read each one before you run it.
Steps
-
git statuswhat changed, staged or not
-
git restore file.txtdanger throw away one file's changes
-
git restore --staged file.txtdanger unstage it, keeping the changes
-
git stashput every change aside; git stash pop brings them back
-
git clean -ndlist the new files git does not track
-
git clean -fddanger delete them
-
git reset --harddanger throw away every change to tracked files
Notes
- restore, clean -fd and reset --hard cannot be undone for changes never committed.
Commands used
git
Each has a page in lore: lore git opens it.