Git
简体中文 ▾ Topics ▾ Latest version ▾ git-clean last updated in 2.43.2

名称

git-clean - 删除工作目录树中未跟踪的文件

概述

git clean [-d] [-f] [-i] [-n] [-q] [-e <模式>] [-x | -X] [--] <路径规范>…​

描述

从当前目录开始,通过递归删除不在版本控制之下的文件来清理工作区。

通常情况下,只有 Git 未知的文件会被删除,但如果指定了 -x 选项,被忽略的文件也会被删除。例如,这对删除所有构建产品很有用。

如果给出任何可选的`<路径规范>…​`参数,只有那些与路径规范相匹配的路径会受到影响。

选项

-d

Normally, when no <pathspec> is specified, git clean will not recurse into untracked directories to avoid removing too much. Specify -d to have it recurse into such directories as well. If a <pathspec> is specified, -d is irrelevant; all untracked files matching the specified paths (with exceptions for nested git directories mentioned under --force) will be removed.

-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 or -i. Git will refuse to modify untracked nested git repositories (directories with a .git subdirectory) unless a second -f is given.

-i
--interactive

显示会做什么,并以交互方式清理文件。详见 “交互模式”。

-n
--dry-run

实际上不要删除任何东西,只是显示会做什么。

-q
--quiet

要安静,只报告错误,但不报告成功删除的文件。

-e <模式>
--exclude=<模式>

在标准的忽略规则之外,使用给定的排除模式(见 gitignore[5])。

-x

Don’t use the standard ignore rules (see gitignore[5]), but still use the ignore rules given with -e options from the command line. This allows removing all untracked files, including build products. This can be used (possibly in conjunction with git restore or git reset) to create a pristine working directory to test a clean build.

-X

Remove only files ignored by Git. This may be useful to rebuild everything from scratch, but keep manually created files.

交互模式

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

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:

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

你也可以在上面输入 cclean,只要选择是唯一的。

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

清理

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

按模式过滤

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

按数字选择

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 items are selected. 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.

逐一询问

这将开始进行清理,你必须逐一确认,以便删除项目。请注意,这个动作没有上述两个动作那么有效。

退出

这样,您就可以在不做任何清洁的情况下退出。

帮助

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

配置

Warning

Missing zh_HANS-CN/includes/cmd-config-section-all.txt

See original version for this content.

Warning

Missing zh_HANS-CN/config/clean.txt

See original version for this content.

参见

GIT

属于 git[1] 文档

scroll-to-top