Is there a git command to revert all uncommitted changes in a working tree and index and to also remove newly created files and folders?
The "restore" command helps to unstage or even discard uncommitted local changes. On the one hand, the command can be used to undo the effects of git add and unstage changes you have previously added to the Staging Area.
Use git reset to Remove Uncommitted Changes in Git Another way to remove uncommitted changes using git reset is with option --hard and params HEAD . The --hard option specifies Git to throw ALL changes between the current state and the commit in the last argument.
You can run these two commands:
# Revert changes to modified files. git reset --hard # Remove all untracked files and directories. # '-f' is force, '-d' is remove directories. git clean -fd
If you want to revert the changes only in current working directory, use
git checkout -- .
And before that, you can list the files that will be reverted without actually making any action, just to check what will happen, with:
git checkout --
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With