小编典典

git:撤消所有工作目录更改,包括新文件

all

如何从工作目录中删除所有更改,包括新的未跟踪文件。我知道这样git checkout -f做,但它不会删除自上次提交以来创建的新的未跟踪文件。

有人知道怎么做吗?


阅读 107

收藏
2022-02-25

共1个答案

小编典典

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)

要事先查看将要删除的内容,而不是实际删除它,请使用-n标志(这基本上是一个测试运行)。当您准备好实际删除时,请删除该-n标志:

git clean -nfd

2022-02-25