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?
Please note that there might still be files that won't seem to disappear - they might be unedited, but git might have marked them as being edited because of CRLF / LF changes. See if you've made some changes in .gitattributes
recently.
In my case I've added CRLF settings into the .gitattributes
file and all the files remained in the "modified files" list because of this. Changing the .gitattributes settings made them disappear.
From Git help:
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
If you have an uncommitted change (its only in your working copy) that you wish to revert to the copy in your latest commit, do the following:
git checkout filename
I usually use this way that works well:
mv fold/file /tmp
git checkout fold/file
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.rb
modified: app/views/posts/index.html.erb
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 --