「git-clean」

  LINUX MANUAL PAGES

git-clean,从工作树中删除未跟踪的文件。

命令行语法格式(SYNOPSIS)

git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [–] <path>…

命令描述(DESCRIPTION)

Cleans the working tree by recursively removing files that are not under version control, starting from the
current directory.

Normally, only files unknown to Git are removed, but if the -x option is specified, ignored files are also
removed. This can, for example, be useful to remove all build products.

If any optional <path>… arguments are given, only those paths are affected.

命令支持的选项及含义(OPTIONS)

-d
删除未跟踪的目录以及未跟踪的文件
如果未跟踪的目录由不同的Git仓库管理,则默认情况下不会删除它。如果要删除这样的目录,使用两次-f选项。

-f, –force
如果Git中,未配置变量clean.requireForce为false,git clean将拒绝删除文件或目录,除非给出了-f、-n、-i。
Git将拒绝删除具有.git子目录或文件的目录,除非给出了第二个-f选项。

-i, –interactive
以交互方式显示将要执行的动作和清除的文件。参阅“INTERACTIVE MODE”。

-n, –dry-run
不进行实际的删除动作,只是显示将会执行的动作。

-q, –quiet
安静模式,只报告错误,但不是成功删除的文件。

-e <pattern>, –exclude=<pattern>
除了在每个目录中的.gitignore$GIT_DIR/info/exclude外,对<pattern>规则指定的文件或者目录也进行忽略。

-x
不要使用从.gitignore(每个目录)和$GIT_DIR/info/exclude读取的忽略规则,但仍然使用-e选项给出的忽略规则。
这允许删除所有未跟踪的文件,包括构建时的输出。这可以使用(可能与git reset一起)来创建一个原始的工作目录来测试一次“干净的构建”。

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

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:

*
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 c or clean above as long as the choice is unique.

The main command loop has 6 subcommands.

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-separated 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.

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 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.

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.

相关文档(SEE ALSO)

gitignore(5)

GIT

Part of the git(1) suite

参考文献