How to revert uncommitted changes including files and folders? How to revert uncommitted changes including files and folders? git git

How to revert uncommitted changes including files and folders?


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 --


Use "git checkout -- ..." to discard changes in working directory

git checkout -- app/views/posts/index.html.erb

or

git checkout -- *

removes all changes made to unstaged files in git status eg

modified:    app/controllers/posts.rbmodified:    app/views/posts/index.html.erb