如何从当前工作树中删除未追踪的本地文件?
当前回答
用途: 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 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 clean -fdn
这将向您展示将被删除的文件列表. 现在实际上删除这些文件使用这个命令:
git clean -fd
如果您只想删除被“吉特状态”追踪的文件
git stash save -u
git stash drop "stash@{0}"
我更喜欢“清洁”这个,因为“清洁”会删除被Git忽略的文件,所以你的下一个构建将不得不重建一切,你可能会失去你的IDE设置。
在运行清洁命令之前,总是使用 -n,因为它会向您展示哪些文件会被删除。
通常情况下,当没有确定的情况下,Git Clean 不会返回未跟踪的目录,以避免删除太多。 指定 -d 以便返回此类目录。 如果任何路径是确定的, -d 是无关紧要的; 所有未跟踪的文件符合确定的路径(除非在 --force 中提到的未跟踪的Git目录)将被删除。
git clean -n -d
git clean -n -d -f
git clean -d -f
默认情况下, git clean 只会删除未追踪的文件,这些文件不会被忽视. 任何符合您的.gitignore 或其他 ignore 文件中的模式的文件将不会被删除. 如果您想要删除这些文件,您可以将 -x 添加到清洁命令。
git clean -f -d -x
git clean -x -i
If you are not 100% sure that deleting your uncommitted work is safe, you could use stashing instead
git stash --all
git stash push --keep-index
呼叫 git stash 没有任何论点,相当于 git stash push。
git stash push -m "name your stash" // before git stash save (deprecated)
git stash drop // or clean
要查看关于如何使用 stash 的完整指示,请参见此 如何在 git 中以名称命名和获取 stash?
取消完整的更改 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添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- 在GitHub上有一个公共回购的私人分支?
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式