git clean:“不会删除”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8638562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:17:54  来源:igfitidea点击:

git clean: What does "Would not remove" mean?

gitgit-clean

提问by nonot1

When I run git clean --dry-runthe results are a bit like:

当我运行时git clean --dry-run,结果有点像:

Would remove an_untracked_file
Would remove an_untracked_file_2
Would not remove some_unrelated_folder/subfolder/

The "unrelated" folders are tracked and have had no changes, so I would not expect git to remove them.

“无关”文件夹被跟踪并且没有任何更改,所以我不希望 git 删除它们。

But, why does git report Would not removefor some, but not all, of my project's normal (and totally untouched) folders?

但是,为什么 git 会报告Would not remove我项目的一些(而不是全部)正常(并且完全未受影响)的文件夹?

Can I tell what is causing git to consider, but then decide against, removing them?

我能说出是什么导致 git 考虑,然后决定反对,删除它们吗?

git statuslists only the couple of un-tracked files I know about. As expected.

git status仅列出我所知道的几个未跟踪的文件。正如预期的那样。

git ls-files --other --exclude-standardreturns those same un-tracked files. As expected.

git ls-files --other --exclude-standard返回那些相同的未跟踪文件。正如预期的那样。

git ls-files --other --exclude-standard --directoryreturns those same un-tracked files, plus a bunch of seemingly normal directories. This is not what I expected to see since I thought the purpose of--directorywas to reduce, not increase the number of results returned.

git ls-files --other --exclude-standard --directory返回那些相同的未跟踪文件,以及一堆看似正常的目录。这不是我期望看到的,因为我认为目的--directory减少而不是增加返回的结果数量。

Upon spot checking the unexpected directories, it seems each one is empty, except for a ".gitignore"d .svn sub-folder. Perhaps this factors in to things.

在现场检查意外目录时,似乎每个目录都是空的,除了“.gitignore”d .svn 子文件夹。也许这会影响事物。

Can anyone help me understand this behavior?

谁能帮我理解这种行为?

Thank you

谢谢

回答by Lily Ballard

By default, git cleandoesn't remove folders. It's telling you that it sees an untracked folder, but it won't remove it. Give it the -dflag to instruct it to remove directories as well, as in git clean -d -n

默认情况下,git clean不删除文件夹。它告诉您它看到一个未跟踪的文件夹,但不会将其删除。给它一个-d标志来指示它也删除目录,如git clean -d -n

回答by VonC

Can I tell what is causing git to consider, but then decide against, removing them?

我能说出是什么导致 git 考虑,然后决定反对,删除它们吗?

You actually can! (Since July, 2013, upcoming git 1.8.4):
"git clean" command learned an interactive mode.

你真的可以!(自 2013 年 7 月起,即将发布 git 1.8.4):
git clean”命令学习了交互模式。

See commit 17696002086e8c6b9e998543d212e707c7d511abfor the initial implementation:

初始实现见提交 17696002086e8c6b9e998543d212e707c7d511ab

See commit d1239264f2786d7ea15543b980c6bf6afbc4701afor the implementation:

实现见提交 d1239264f2786d7ea15543b980c6bf6afbc4701a

Add a new action for interactive git-clean: filter by pattern.
When the user chooses this action, user can input space-separated patterns (the same syntax as gitignore), and each clean candidate that matches with one of the patterns will be excluded from cleaning.
When the user feels it's OK, presses ENTER and backs to the confirmation dialog.

添加一个新的交互操作git-clean按模式过滤
当用户选择此操作时,用户可以输入空格分隔的模式(与 语法相同gitignore),每个与其中一个模式匹配的干净候选者将被排除在清除之外。
当用户觉得没问题时,按 ENTER 并返回到确认对话框。

See commit db627fd568410499c47d764937c3d7a10bbadffafor tests and examples.

有关测试和示例,请参阅提交 db627fd568410499c47d764937c3d7a10bbaddfa

See commit c0be6b4c8a1d16a92efad00d73683075cf2da60dfor the documentation

有关文档,请参阅提交 c0be6b4c8a1d16a92efad00d73683075cf2da60d

Show what would be done and clean files interactively.

显示将要完成的操作并以交互方式清理文件。



Interactive mode

交互模式

When the command enters the interactive mode, it shows the files and directories to be cleaned, and goes into its interactive command loop.

The command loop shows the list of subcommands available, and gives a prompt "What now>".
In general, when the prompt ends with a single '>', you can pick only one of the choices given and type return, like this:

当命令进入交互模式时,它会显示要清理的文件和目录,并进入其交互命令循环。

命令循环显示可用的子命令列表,并给出提示“ What now>”。
通常,当提示以单个 ' >'结尾时,您只能选择给定的选项之一并键入return,如下所示:

------------
  *** Commands ***
  1: clean                2: filter by pattern    3: select by numbers
  4: ask each             5: quit                 6: help
  What now> 1
------------

You also could say cor cleanabove as long as the choice is unique.

The main command loop has 6 subcommands.

只要选择独特,您也可以说cclean高于。

主命令循环有 6 个子命令。

clean::

Start cleaning files and directories, and then quit.

开始清理文件和目录,然后退出。

filter by pattern::

This shows the files and directories to be deleted and issues an "Input ignore patterns>>" prompt.
You can input space-seperated patterns to exclude files and directories from deletion.
E.g. "*.c *.h" will excludes files end with ".c" and ".h" from deletion.
When you are satisfied with the filtered result, press ENTER(empty) back to the main menu.

这将显示要删除的文件和目录并发出“ Input ignore patterns>>”提示。
您可以输入以空格分隔的模式以排除删除的文件和目录。
例如,“ ”将从删除中*.c *.h排除以“ .c”和“ .h”结尾的文件。
当您对过滤结果感到满意时,按ENTER(空)返回主菜单。

select by numbers

This shows the files and directories to be deleted and issues an "Select items to delete>>" prompt.
When the prompt ends with double '>>' like this, you can make more than one selection, concatenated with whitespace or comma.
Also you can say ranges.
E.g. "2-5 7,9" to choose 2,3,4,5,7,9 from the list.
If the second number in a range is omitted, all remaining patches are taken.
E.g. "7-" to choose 7,8,9 from the list.
You can say '*' to choose everything.
Also when you are satisfied with the filtered result, press ENTER(empty) back to the main menu.

这将显示要删除的文件和目录并发出“ Select items to delete>>”提示。
当提示>>像这样以双 ' '结尾时,您可以进行多个选择,并用空格或逗号连接。
你也可以说范围。
例如“ 2-5 7,9”从列表中选择 2,3,4,5,7,9。
如果省略范围中的第二个数字,则采用所有剩余的补丁。
例如“ 7-”从列表中选择 7,8,9。
你可以说“ *”来选择一切。
此外,当您对过滤结果感到满意时,按ENTER(空)返回主菜单。

ask each::

This will start to clean, and you must confirm one by one in order to delete items.
Please note that this action is not as efficient as the above two actions.

这样就开始清理了,必须一一确认才能删除项目。
请注意,此操作不如上述两个操作有效。

quit::

This lets you quit without do cleaning.

这让您无需清洁即可退出。

help::

Show brief usage of interactive git-clean.

显示交互式 git-clean 的简要用法。

回答by Adrian Sanoguel

If certain files and folders continue to fail when executing the command, then run a

如果执行命令时某些文件和文件夹继续失败,则运行

git clean -d -f

git clean -d -f

The -fwould force the operation.

-f会强制执行该操作。

Use -nfor a dry run.

使用-n一个预演

回答by Andriy Drozdyuk

This answer is mainly for reference purposes, as I think it's the most common scenario for cleaning up your repo dir.

这个答案主要用于参考目的,因为我认为这是清理 repo 目录的最常见场景。

To remove all untracked directories recursively:

递归删除所有未跟踪的目录:

git clean -d -f -x

git clean -d -f -x

-dfor directories, -xfor removing directories in your ignore list too (things like binand build), which is what I need most of the time and -fto confirm you know what you're doing.

-d对于目录,也 -x用于删除忽略列表中的目录(例如binbuild),这是我大多数时候需要的,并 -f确认您知道自己在做什么。

回答by johan.i.zahri

i'm using git version 2.10.0 on mac, and somehow i can not use

我在 mac 上使用 git 版本 2.10.0,但不知何故我无法使用

git clean -df

git clean -df

to remove the untracked files, so i used this instead:

删除未跟踪的文件,所以我改用它:

git checkout --

git 结帐——

PS:

PS:

if anyone can explain in the comments why i'm not able to use

如果有人可以在评论中解释为什么我不能使用

git clean -df

git clean -df

to remove the files, i'd be very appreciative..thanks

要删除文件,我将不胜感激..谢谢

WARNING you will also lose your tracked files :(

警告您还将丢失跟踪的文件:(