如何从当前工作树中删除未追踪的本地文件?
当前回答
对于我来说,只有下一个工作:
git clean -ffdx
在所有其他情况下,我收到一些子办公室的“Skipping Directory”消息。
其他回答
要删除未追踪的文件,您应该首先使用命令查看将受清洁影响的文件。
git clean -fdn
这将向您展示将被删除的文件列表. 现在实际上删除这些文件使用这个命令:
git clean -fd
git-clean 是你正在寻找的,它被用来从工作树中删除未追踪的文件。
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 列表中删除所有未追踪的文件。
在此 repo + 子模块中删除所有额外的文件和文件
这将使你处于新鲜的克隆状态。
git clean -ffdx
在此 repo 中删除所有额外的文件夹和文件,但不是其子模块
git clean -fdx
删除额外的文件夹,但不删除文件(例如构建或登录文件夹)
git clean -fd
删除额外的文件夹 + 被忽略的文件(但不新添加的文件)
如果文件没有被忽视,并且还没有被检查,那么它仍然存在。
git clean -fdX
新互动模式
git clean
git clean -f -d -x $(git rev-parse --show-cdup)适用于干净的根目录,无论你在哪里呼叫它在仓库目录树内。
确保 -f、 -d、 -x 旗帜符合您的需求:
-d
Remove untracked directories in addition to untracked files. If an
untracked directory is managed by a different Git repository, it is
not removed by default. Use -f option twice if you really want to
remove such a directory.
-f, --force
If the Git configuration variable clean.requireForce is not set to
false, git clean will refuse to delete files or directories unless
given -f, -n or -i. Git will refuse to delete directories with .git
sub directory or file unless a second -f is given. This affects
also git submodules where the storage area of the removed submodule
under .git/modules/ is not removed until -f is given twice.
-x
Don't use the standard ignore rules read from .gitignore (per
directory) and $GIT_DIR/info/exclude, but do still use the ignore
rules given with -e options. This allows removing all untracked
files, including build products. This can be used (possibly in
conjunction with git reset) to create a pristine working directory
to test a clean build.
还有其他旗帜也可用,只需检查 git clean --help。
推荐文章
- 如何配置Mac OS X术语,使git有颜色?
- Visual Studio Code: .git文件夹/文件隐藏
- “node_modules”文件夹应该包含在git存储库中吗
- 为什么git-rebase给了我合并冲突,而我所做的只是压缩提交?
- 当我试图推到原点时,为什么Git告诉我“没有这样的远程‘原点’”?
- 如何从远程分支中挑选?
- 如何查看一个分支中的哪些提交不在另一个分支中?
- 如何取消在github上的拉请求?
- HEAD和master的区别
- GIT克隆在windows中跨本地文件系统回购
- RPC失败;卷度传输已关闭,剩余未完成的读取数据
- 我应该在.gitignore文件中添加Django迁移文件吗?
- 错误:您对以下文件的本地更改将被签出覆盖
- Git rebase—即使所有合并冲突都已解决,仍然会继续报错
- 在Git中,我如何知道我的当前版本是什么?