我如何从当前工作树中删除未跟踪的本地文件 ?
当前回答
哦,我,我,我,Zsh与zzsh 千兆赫通过 git 插件提供这些伟大的别名。 它们也可以在狂欢中使用 。
gclean='git clean -fd'
gpristine='git reset --hard && git clean -dfx'
gclean
除去未跟踪文件之外未跟踪的目录.gpristine
硬重置本地更改, 删除未跟踪的目录, 未跟踪的文件不要使用从.gitignore( 每一个目录) 和 $GIT_ DIR/ info/ excluldude 读取的标准忽略规则, 但是仍然使用给 - e 选项的忽略规则。 这样可以删除所有未跟踪的文件, 包括构建产品。 这可以用来( 可能与 Git 重设结合) 创建一个纯净的工作目录, 测试干净的构建 。.
其他回答
如果需要从特定的子目录中删除未跟踪的文件,
git clean -f {dir_path}
并合并删除未跟踪的 dir/ file 和被忽略的文件 。
git clean -fxd {dir_path}
在此之后, 您将只对文件进行修改git status
.
在实际删除之前先知道要删除的内容:
git clean -d -n
它将产生类似的东西:
将删除样本. txt
删除上一个命令输出中列出的所有内容 :
git clean -d -f
它将产生类似的东西:
删除样本. txt
OK,OK, OK, OK, OK, OK, OK, OK, OK,OK, OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK,删除删除未跟踪的自定义文件及文件夹容易使用git
在命令行中,按这样做:
git clean -fd
双检查在这样做之前, 它会删除文件和文件夹, 而不创建任何历史...
在本案中-f
代表武力和-d
代表目录...
所以,如果只删除文件,您可以使用-f
仅 :
git clean -f
如果您想要删除删除(目录) 和文件, 您只能删除未跟踪的目录和文件 :
git clean -fd
还有,你也可以用-x
添加被 git 忽略的文件。 如果您想要删除所有文件, 这将很有帮助 。
并添加-i
git 请求您逐个删除文件的许可 。
如果您不确定并想要先检查事项,请添加-n
旗帜。
使用使用-q
如果您不想在成功删除后看到任何报告。
我还创造了下面的图像 让它更令人难忘 尤其是我见过很多人混淆-f
有时是用来清理文件夹或把它混为一谈的!
我用这个:
git status
- 复制文件的路径
rm <path of file>
我的项目有很多由巨大的 ANT 构建脚本创建的文件。 使用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
.
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的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日志日期格式