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


当前回答

清除 Git 仓库和所有子模块

以下命令将清除当前 git 仓库及其所有子模块的递归 :

(git clean -d -x -f && git submodule foreach --recursive git clean -d -x -f)

其他回答

git-清洁这是您正在寻找的。 它用于从工作树上移除未跟踪的文件 。

我喜欢git stash push -u因为你可以用git stash pop.

我还找到了一种方法 在藏物中显示未追踪的文件(例如:git show stash@{0}^3) https://stackoverflow.com/a/12681856/338986

内容2:git stash save将作有利于push谢谢 @timp-wolf.

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

git clean -fdn

这将显示要删除的文件列表。 现在要实际删除那些使用此命令的文件 :

git clean -fd

我认为安全和容易的方法就是这个!

git add .
git stash 

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