我如何从当前工作树中删除未跟踪的本地文件 ?
当前回答
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 -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 -f -d
以确保目录目录目录目录也删除。
不要删除任何东西, 只显示会做什么。
git clean -n
或
git clean --dry-run
除未跟踪的文件外,删除未跟踪的目录。如果一个未跟踪的目录由不同的 Git 仓库管理,则默认不会删除。使用该目录。
-f
如果您真的想要删除此目录, 选项将两次 。git clean -fd
然后您可以检查您的文件是否真的已删除git status
.
使用git reset HEAD <file>
以卸开一个文件
执行`基本干净'指挥时要小心。
总是使用 -n
第一次
总是使用-n
在运行干净命令前, 它会显示要删除的文件 。
-d
通常情况下, 当未指定时, git clean 将不会在未跟踪的目录中循环, 以避免删除太多内容。 指定 - 指定它也会在目录中循环。 如果指定了任何路径, - d 是无关的; 所有匹配指定路径的未跟踪文件都将被删除( 强制下提及的嵌套 git 目录除外 ) 。
-f
| --force
如果 Git 配置变量清洁. require Force 不设假, Git clean 将拒绝删除文件或目录, 除非给 -f 或 -i。 Git 将拒绝修改未跟踪的嵌套 Git 仓库( 带有. git 子目录的目录) , 除非给第二个 - f 。
git clean -n -d
git clean -n -d -f
现在没有跑-n
如果输出是您要删除的 。
git clean -d -f
默认情况下,git clean
只会删除未被忽略的未追踪文件 。 任何符合您. gitignore 或其他忽略文件模式的文件都不会被删除。 如果您也想要删除这些文件, 您可以添加一个-x
向干净的命令。
git clean -f -d -x
还有一个互动模式可以使用-i
使用干净命令
git clean -x -i
或
如果您不能100%确定删除您未委托的工作是否安全, 您可以用藏匿代替git stash --all
在使用前stash --all
注:如果--all
选项,然后忽略被忽略的文件除防污装置外,还加以藏匿和清洗。未跟踪文件.
git stash push --keep-index
如果使用 -- kep- index 选项, 索引中已经添加的所有更改将保持不变。 您的分阶段更改将留在工作空间中, 但与此同时, 这些更改也将保存在您的隐藏中 。
电 电 电git stash
没有任何论据等于或等于或等于或等于或等于git stash push
.
git stash push -m "name your stash" // before git stash save (deprecated)
基于用过的旗旗的嵌入基于用过的旗子的嵌入可以将您的目录从未显示/ 高级文件清除出来, 将其写入隐藏存储文件 。 我给您在任何时间点使用文件的灵活性 。 @ info: tooltip隐藏与适用或弹出。然后,如果您可以删除您的隐藏文件,您可以运行:
git stash drop // or clean
看到关于如何与藏藏合作的完整指导 可以看到这一点如何在 Git 中点名并检索隐藏的 名称 ?
要删除未跟踪的文件, 您应该首先使用命令查看将受到清理影响的文件
git clean -fdn
这将显示要删除的文件列表。 现在要实际删除那些使用此命令的文件 :
git clean -fd
推荐文章
- 为什么调用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有什么区别?