如何从当前工作树中删除未追踪的本地文件?
当前回答
用途: git clean [-d] [-f] [-i] [-n] [-q] [-e ] [-x♰ -X] [--]...
-q, --quiet do not print names of files removed
-n, --dry-run dry run
-f, --force force
-i, --interactive interactive cleaning
-d remove whole directories
-e, --exclude <pattern>
add <pattern> to ignore rules
-x remove ignored files, too
-X remove only ignored files
其他回答
删除未追踪的文件的简单方法
要删除所有未追踪的文件,简单的方式是先添加所有文件并重新设置下面的复制文件。
git add --all
git reset --hard HEAD
如果您只想删除被“吉特状态”追踪的文件
git stash save -u
git stash drop "stash@{0}"
我更喜欢“清洁”这个,因为“清洁”会删除被Git忽略的文件,所以你的下一个构建将不得不重建一切,你可能会失去你的IDE设置。
git clean -f
将从当前 git 中删除未追踪的文件
git clean -fd
当您要删除目录和文件时,此只会删除未追踪的目录和文件。
用途: git clean [-d] [-f] [-i] [-n] [-q] [-e ] [-x♰ -X] [--]...
-q, --quiet do not print names of files removed
-n, --dry-run dry run
-f, --force force
-i, --interactive interactive cleaning
-d remove whole directories
-e, --exclude <pattern>
add <pattern> to ignore rules
-x remove ignored files, too
-X remove only ignored files
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 列表中删除所有未追踪的文件。