我如何从当前工作树中删除未跟踪的本地文件 ?
当前回答
我喜欢用git stash
命令,稍后您可以得到隐藏的文件和更改。git clean
这也是一个很好的选择, 但完全取决于您的要求。 这是关于 Git 藏藏和 Git 干净的解释,7.3 Git 工具 - 粉刷和清洁
其他回答
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
.
如果您只想删除列表中未被“ gitt status” 跟踪的文件
git stash save -u
git stash drop "stash@{0}"
我更喜欢这个而不是“ 开始清理” , 因为“ 开始清理” 将会删除被忽略的文件, 所以您的下一栋建筑必须重建一切, 您也可能丢失您的 IDE 设置 。
我用这个:
git status
- 复制文件的路径
rm <path of file>
我的项目有很多由巨大的 ANT 构建脚本创建的文件。 使用git clean
会造成混乱
清除未跟踪文件的简单方式
要删除所有未跟踪的文件,简单的方法就是先加全部和重置重置( R)如下所示
git add --all
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或-- 干燥运行检查它能做什么
推荐文章
- 为什么git-rebase给了我合并冲突,而我所做的只是压缩提交?
- 当我试图推到原点时,为什么Git告诉我“没有这样的远程‘原点’”?
- 如何从远程分支中挑选?
- 如何查看一个分支中的哪些提交不在另一个分支中?
- 如何取消在github上的拉请求?
- HEAD和master的区别
- GIT克隆在windows中跨本地文件系统回购
- RPC失败;卷度传输已关闭,剩余未完成的读取数据
- 我应该在.gitignore文件中添加Django迁移文件吗?
- 错误:您对以下文件的本地更改将被签出覆盖
- Git rebase—即使所有合并冲突都已解决,仍然会继续报错
- 在Git中,我如何知道我的当前版本是什么?
- 跟踪所有远程git分支作为本地分支
- 自定义SSH端口上的Git
- git如何显示不存在于.gitignore中的未跟踪文件