git: undo all working dir changes including new files
How to delete all changes from working directory including new untracked files. I know that git checkout -f
does that, but it doesn't delete new untracked files created since last commit.
Does anybody have an idea how to do that?
git reset --hard # removes staged and working directory changes
## !! be very careful with these !!
## you may end up deleting what you don't want to
## read comments and manual.
git clean -f -d # remove untracked
git clean -f -x -d # CAUTION: as above but removes ignored files like config.
git clean -fxd :/ # CAUTION: as above, but cleans untracked and ignored files through the entire repo (without :/, the operation affects only the current directory)
最经常使用的最安全的方法:
git clean -fd
For all unstaged files use:
git checkout -- .
The .
at the end is important.
You can replace .
with a sub-directory name to clear only a specific sub-directory of your project. The problem is addressed specifically here.
上一篇: 通过合并覆盖以下未跟踪的工作树文件
下一篇: git:撤消所有工作目录更改,包括新文件