我如何从当前工作树中删除未跟踪的本地文件 ?
当前回答
删除此 repo + 子模块中的所有额外文件夹和文件
这让你和新克隆人处于同样的状态
git clean -ffdx
删除此回调中的全部额外文件夹和文件, 但不删除子模块
git clean -fdx
删除额外的文件夹, 但不包括文件( 如: 构建或日志文件夹) 。
git clean -fd
删除额外文件夹 + 忽略的文件(但不是新添加的文件)
如果文件没有被忽略, 还没有被检查, 那么它会留下来 。 请注意首都 X 。
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
.
我们可以使用下面的 git 评论, 很容易地从当前 git 工作树中删除本地的未跟踪文件 。
git reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]
示例:
git reset --hard HEAD
链接 :
普通普通git clean
命令不会用我的git version 2.9.0.windows.1
.
$ git clean -fdx # doesn't remove untracked files
$ git clean -fdx * # Append star then it works!
要删除未跟踪的文件, 您应该首先使用命令查看将受到清理影响的文件
git clean -fdn
这将显示要删除的文件列表。 现在要实际删除那些使用此命令的文件 :
git clean -fd
如果需要从特定的子目录中删除未跟踪的文件,
git clean -f {dir_path}
并合并删除未跟踪的 dir/ file 和被忽略的文件 。
git clean -fxd {dir_path}
在此之后, 您将只对文件进行修改git status
.
推荐文章
- 为什么调用git分支——unset-upstream来修复?
- Windows git“警告:LF将被CRLF取代”,这是警告尾巴向后吗?
- git中的哈希冲突
- git可以自动在空格和制表符之间切换吗?
- Git暂存文件列表
- 如何将git配置存储为存储库的一部分?
- 如何修改GitHub拉请求?
- 如何在Github和本地删除最后n次提交?
- 我如何调试git/git-shell相关的问题?
- 错误:无法使用rebase进行拉取:您有未分阶段的更改
- Git隐藏未缓存:如何把所有未分期的变化?
- 真实的恶魔
- 如何从另一个分支获得更改
- Git:权限被拒绝(publickey)致命-无法从远程存储库读取。克隆Git存储库时
- git reflog和log有什么区别?