如何从当前工作树中删除未追踪的本地文件?


当前回答

取消完整的更改 git clean -f -d

$ git clean -f -d
Removing client/app/helpers/base64.js
Removing files/
Removing package.json.bak

where 
-f is force 
-d is a directory 

其他回答

git add --all, git stash and git stash drop, try these three commands in this order in order to remove all untracked files. 通过添加所有这些未追踪的文件到 git 并 stashing 它们将移动所有这些未追踪的文件到 stash 列表并下载顶部一个,即, stash@{0} 将从 stash 列表中删除所有未追踪的文件。

这是我一直使用的:

git clean -fdx

对于一个非常大的项目,你可能想运行它几次。

如果需要从特定子目录中删除未追踪的文件,

git clean -f {dir_path}

并结合的方式来删除未追踪的Dir/文件和被忽略的文件。

git clean -fxd {dir_path}

此后,您将仅在 git 状态中修改文件。

git-clean 是你正在寻找的,它被用来从工作树中删除未追踪的文件。

oh-my-zsh 与 zsh 提供这些伟大的联盟通过 git 插件. 它们也可以在 bash 中使用。

gclean='git clean -fd' gpristine='git reset --hard && git clean -dfx'

gclean 除去未追踪的目录除了未追踪的文件. gpristine 硬重定义本地变更,删除未追踪的目录,未追踪的文件,不要使用从.gitignore (每个目录) 和 $GIT_DIR/info/exclude 阅读的默认忽略规则,但仍然使用与 -e 选项提供的忽略规则。