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


当前回答

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 stash push -u 因为你可以用 git stash pop 放下它们。

编辑: 我也找到了一个方法,以显示未追踪的文件在一个插件(例如 git 显示 stash@{0}^3) https://stackoverflow.com/a/12681856/338986

EDIT2: git stash save 被推翻为 push. 谢谢 @script-wolf。

git clean -f 从工作目录中删除未追踪的文件。

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

我认为最安全、最容易的方式就是这样!

git add .
git stash 

更多信息 https://www.atlassian.com/git/tutorials/saving-changes/git-stash#stashing-your-work

更好的方法是使用: git clean

git clean -d -x -f

这将删除未追踪的文件,包括目录(d)和由 git(x)忽略的文件。

此外,将 -f 论点替换为 -n 以进行干燥运行或 -i 为互动模式,它会告诉你什么将被删除。

要删除未追踪的文件,您应该首先使用命令查看将受清洁影响的文件。

git clean -fdn

这将向您展示将被删除的文件列表. 现在实际上删除这些文件使用这个命令:

git clean -fd