How can I undo every change made to my directory after the last commit, including deleting added files, resetting modified files, and adding back deleted files?
First reset the changes
git reset HEAD --hard
then clean out everything untracked. If you want to keep files that are not tracked due to .gitignore, be careful with this command.
git clean -fd
How can I undo every change made to my directory after the last commit, including deleting added files, resetting modified files, and adding back deleted files?
You can undo changes to tracked files with:
git reset HEAD --hardYou can remove untracked files with:
git clean -fYou can remove untracked files and directories with:
git clean -fdbut you can't undo change to untracked files.
You can remove ignored and untracked files and directories
git clean -fdxbut you can't undo change to ignored files.
You can also set clean.requireForce to false:
git config --global --add clean.requireForce false
to avoid using -f (--force) when you use git clean.
来源:https://stackoverflow.com/questions/4630312/reset-all-changes-after-last-commit-in-git