我如何从当前工作树中删除未跟踪的本地文件 ?
当前回答
(d) [-f] [-n] [-q] [-e] [-x -X] [-]...
-q, --quiet do not print names of files removed
-n, --dry-run dry run
-f, --force force
-i, --interactive interactive cleaning
-d remove whole directories
-e, --exclude <pattern>
add <pattern> to ignore rules
-x remove ignored files, too
-X remove only ignored files
其他回答
删除此 repo + 子模块中的所有额外文件夹和文件
这让你和新克隆人处于同样的状态
git clean -ffdx
删除此回调中的全部额外文件夹和文件, 但不删除子模块
git clean -fdx
删除额外的文件夹, 但不包括文件( 如: 构建或日志文件夹) 。
git clean -fd
删除额外文件夹 + 忽略的文件(但不是新添加的文件)
如果文件没有被忽略, 还没有被检查, 那么它会留下来 。 请注意首都 X 。
git clean -fdX
新的互动模式
git clean
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 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 stash push -u
因为你可以用git stash pop
.
我还找到了一种方法 在藏物中显示未追踪的文件(例如:git show stash@{0}^3
) https://stackoverflow.com/a/12681856/338986
内容2:git stash save
将作有利于push
谢谢 @timp-wolf.
执行`基本干净'指挥时要小心。
总是使用 -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添加?
- 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日志日期格式