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


当前回答

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 选项提供的忽略规则。

其他回答

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

git clean -f

将从当前 git 中删除未追踪的文件

git clean -fd

当您要删除目录和文件时,此只会删除未追踪的目录和文件。

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 -f 从工作目录中删除未追踪的文件。

我在我的博客中包含了一些基本内容, git-intro-basic-commands

要知道在实际删除之前会删除什么:

清洁 -d -n

它会产生这样的东西:

将移除 sample.txt

要删除前命令输出中列出的所有内容:

清洁 -d -f

它会产生这样的东西:

删除 sample.txt