我如何从当前工作树中删除未跟踪的本地文件 ?
当前回答
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
.
其他回答
在实际删除之前先知道要删除的内容:
git clean -d -n
它将产生类似的东西:
将删除样本. txt
删除上一个命令输出中列出的所有内容 :
git clean -d -f
它将产生类似的东西:
删除样本. txt
使用使用git clean -f -d
以确保目录目录目录目录也删除。
不要删除任何东西, 只显示会做什么。
git clean -n
或
git clean --dry-run
除未跟踪的文件外,删除未跟踪的目录。如果一个未跟踪的目录由不同的 Git 仓库管理,则默认不会删除。使用该目录。
-f
如果您真的想要删除此目录, 选项将两次 。git clean -fd
然后您可以检查您的文件是否真的已删除git status
.
要删除未跟踪的文件 :
git add .
git reset --hard HEAD
用户互动办法:
git clean -i -fd
Remove .classpath [y/N]? N
Remove .gitignore [y/N]? N
Remove .project [y/N]? N
Remove .settings/ [y/N]? N
Remove src/com/arsdumpgenerator/inspector/ [y/N]? y
Remove src/com/arsdumpgenerator/manifest/ [y/N]? y
Remove src/com/arsdumpgenerator/s3/ [y/N]? y
Remove tst/com/arsdumpgenerator/manifest/ [y/N]? y
Remove tst/com/arsdumpgenerator/s3/ [y/N]? y
- i 用于交互式
-f 用于武力
-d 用于目录
- 被忽略文件的x( 需要时添加)
注: 添加添加添加- n,n或-- 干燥运行检查它能做什么
uggested 命令从 git docs 删除未跟踪的文件是git 干净
git 干净- 从工作树中移除未跟踪的文件
建议的方法:通过使用git clean -i
这样我们就可以控制它。让我们看看剩下的选择。
可用的选项 :
git clean
-d -f -i -n -q -e -x -X (can use either)
解释:
1. - d. d. 与
除未跟踪的文件外, 删除未跟踪的目录。 如果未跟踪的目录由不同的 Git 仓库管理, 默认情况下不会删除。 如果您真的想要删除此目录, 请两次使用 - f 选项 。
2.f, -- 力
如果 Git 配置变量为清洁. require Force 不设假, 除非给 -f, n 或 -i , git clean 将拒绝运行 。
3 -i, -- 互动
以交互方式显示要做什么和清除文件。 详情请见“ 互动模式 ” 。
-n, --dry-run
不要删除任何东西, 只显示会做什么。
- 5q, - 安静
保持安静, 只报告错误, 而不是成功删除的文件 。
-e, --clucte=
除了在.gitignore(每个目录)和$GIT_DIR/info/exclude中发现的图案外,还认为这些图案属于一套现行无视规则。
7. -x
不要使用从.gitignore( 每一个目录) 和 $GIT_ DIR/ info/ exclude 读取的标准忽略规则, 但是仍然使用给定的 - e 选项的忽略规则。 这样可以删除所有未跟踪的文件, 包括建材产品 。 这可以用来( 可能与 Git 重设一起) 创建一个纯净的工作目录以测试清洁的构建 。
8. -X8 -X
只删除被 Git 忽略的文件。 这也许有助于从零开始重建一切, 但保存手动创建的文件 。
推荐文章
- RPC失败;卷度传输已关闭,剩余未完成的读取数据
- 我应该在.gitignore文件中添加Django迁移文件吗?
- 错误:您对以下文件的本地更改将被签出覆盖
- Git rebase—即使所有合并冲突都已解决,仍然会继续报错
- 在Git中,我如何知道我的当前版本是什么?
- 跟踪所有远程git分支作为本地分支
- 自定义SSH端口上的Git
- git如何显示不存在于.gitignore中的未跟踪文件
- Git错误:遇到7个文件应该是指针,但不是
- GitHub克隆与OAuth访问令牌
- 移动(或“撤销”)最后一个git提交到非暂存区域
- 我可以在GitHub上对要点进行拉请求吗?
- Hg:如何做一个像git的rebase
- 如何丢弃远程更改并将文件标记为“已解决”?
- 如何查看远程标签?