Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 1 | git-clean(1) |
| 2 | ============ |
| 3 | |
| 4 | NAME |
| 5 | ---- |
| 6 | git-clean - Remove untracked files from the working tree |
| 7 | |
| 8 | SYNOPSIS |
| 9 | -------- |
| 10 | [verse] |
Jiang Xin | 1769600 | 2013-06-25 23:53:48 +0800 | [diff] [blame] | 11 | 'git clean' [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>... |
Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 12 | |
| 13 | DESCRIPTION |
| 14 | ----------- |
Wesley J. Landaker | 911198f | 2009-04-25 09:13:41 -0600 | [diff] [blame] | 15 | |
Junio C Hamano | 6a260f5 | 2009-05-06 10:48:26 -0700 | [diff] [blame] | 16 | Cleans the working tree by recursively removing files that are not |
| 17 | under version control, starting from the current directory. |
Wesley J. Landaker | 911198f | 2009-04-25 09:13:41 -0600 | [diff] [blame] | 18 | |
Matthieu Moy | 23f8239 | 2016-06-28 13:40:10 +0200 | [diff] [blame] | 19 | Normally, only files unknown to Git are removed, but if the `-x` |
Wesley J. Landaker | 911198f | 2009-04-25 09:13:41 -0600 | [diff] [blame] | 20 | option is specified, ignored files are also removed. This can, for |
| 21 | example, be useful to remove all build products. |
| 22 | |
Abhijit Menon-Sen | f448e24 | 2008-07-30 15:03:43 +0530 | [diff] [blame] | 23 | If any optional `<path>...` arguments are given, only those paths |
| 24 | are affected. |
Junio C Hamano | 393e3b1 | 2006-05-08 12:02:44 -0700 | [diff] [blame] | 25 | |
Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 26 | OPTIONS |
| 27 | ------- |
| 28 | -d:: |
Elijah Newren | e86bbcf | 2019-09-17 09:35:01 -0700 | [diff] [blame] | 29 | Normally, when no <path> is specified, git clean will not |
| 30 | recurse into untracked directories to avoid removing too much. |
| 31 | Specify -d to have it recurse into such directories as well. |
| 32 | If any paths are specified, -d is irrelevant; all untracked |
| 33 | files matching the specified paths (with exceptions for nested |
| 34 | git directories mentioned under `--force`) will be removed. |
Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 35 | |
Josh Triplett | 2122591 | 2007-04-23 17:18:16 -0700 | [diff] [blame] | 36 | -f:: |
René Scharfe | f7aec12 | 2009-08-29 11:05:00 +0200 | [diff] [blame] | 37 | --force:: |
Thomas Ackermann | 2de9b71 | 2013-01-21 20:17:53 +0100 | [diff] [blame] | 38 | If the Git configuration variable clean.requireForce is not set |
Mikko Rapeli | bcd57cb | 2015-02-26 15:16:49 +0200 | [diff] [blame] | 39 | to false, 'git clean' will refuse to delete files or directories |
Elijah Newren | 09487f2 | 2019-09-17 09:35:02 -0700 | [diff] [blame] | 40 | unless given -f or -i. Git will refuse to modify untracked |
| 41 | nested git repositories (directories with a .git subdirectory) |
| 42 | unless a second -f is given. |
Jiang Xin | 1769600 | 2013-06-25 23:53:48 +0800 | [diff] [blame] | 43 | |
| 44 | -i:: |
| 45 | --interactive:: |
Jiang Xin | c0be6b4 | 2013-06-25 23:53:55 +0800 | [diff] [blame] | 46 | Show what would be done and clean files interactively. See |
| 47 | ``Interactive mode'' for details. |
Josh Triplett | 2122591 | 2007-04-23 17:18:16 -0700 | [diff] [blame] | 48 | |
Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 49 | -n:: |
Stephan Beyer | 459cf2e | 2008-06-08 03:36:10 +0200 | [diff] [blame] | 50 | --dry-run:: |
Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 51 | Don't actually remove anything, just show what would be done. |
| 52 | |
| 53 | -q:: |
Stephan Beyer | 459cf2e | 2008-06-08 03:36:10 +0200 | [diff] [blame] | 54 | --quiet:: |
Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 55 | Be quiet, only report errors, but not the files that are |
| 56 | successfully removed. |
| 57 | |
Jared Hance | 07de4eb | 2010-07-20 15:35:56 -0400 | [diff] [blame] | 58 | -e <pattern>:: |
| 59 | --exclude=<pattern>:: |
Denton Liu | 407e768 | 2019-03-07 00:25:28 -0800 | [diff] [blame] | 60 | Use the given exclude pattern in addition to the standard ignore rules |
| 61 | (see linkgit:gitignore[5]). |
Jared Hance | 07de4eb | 2010-07-20 15:35:56 -0400 | [diff] [blame] | 62 | |
Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 63 | -x:: |
Denton Liu | 407e768 | 2019-03-07 00:25:28 -0800 | [diff] [blame] | 64 | Don't use the standard ignore rules (see linkgit:gitignore[5]), but |
| 65 | still use the ignore rules given with `-e` options from the command |
| 66 | line. This allows removing all untracked |
Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 67 | files, including build products. This can be used (possibly in |
Nguyễn Thái Ngọc Duy | 80f537f | 2019-04-25 16:45:58 +0700 | [diff] [blame] | 68 | conjunction with 'git restore' or 'git reset') to create a pristine |
Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 69 | working directory to test a clean build. |
| 70 | |
| 71 | -X:: |
Thomas Ackermann | 2de9b71 | 2013-01-21 20:17:53 +0100 | [diff] [blame] | 72 | Remove only files ignored by Git. This may be useful to rebuild |
Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 73 | everything from scratch, but keep manually created files. |
| 74 | |
Jiang Xin | c0be6b4 | 2013-06-25 23:53:55 +0800 | [diff] [blame] | 75 | Interactive mode |
| 76 | ---------------- |
| 77 | When the command enters the interactive mode, it shows the |
| 78 | files and directories to be cleaned, and goes into its |
| 79 | interactive command loop. |
| 80 | |
| 81 | The command loop shows the list of subcommands available, and |
| 82 | gives a prompt "What now> ". In general, when the prompt ends |
| 83 | with a single '>', you can pick only one of the choices given |
| 84 | and type return, like this: |
| 85 | |
| 86 | ------------ |
| 87 | *** Commands *** |
| 88 | 1: clean 2: filter by pattern 3: select by numbers |
| 89 | 4: ask each 5: quit 6: help |
| 90 | What now> 1 |
| 91 | ------------ |
| 92 | |
| 93 | You also could say `c` or `clean` above as long as the choice is unique. |
| 94 | |
| 95 | The main command loop has 6 subcommands. |
| 96 | |
| 97 | clean:: |
| 98 | |
| 99 | Start cleaning files and directories, and then quit. |
| 100 | |
| 101 | filter by pattern:: |
| 102 | |
| 103 | This shows the files and directories to be deleted and issues an |
Thomas Ackermann | f745acb | 2014-11-03 21:37:07 +0100 | [diff] [blame] | 104 | "Input ignore patterns>>" prompt. You can input space-separated |
Jiang Xin | c0be6b4 | 2013-06-25 23:53:55 +0800 | [diff] [blame] | 105 | patterns to exclude files and directories from deletion. |
| 106 | E.g. "*.c *.h" will excludes files end with ".c" and ".h" from |
| 107 | deletion. When you are satisfied with the filtered result, press |
| 108 | ENTER (empty) back to the main menu. |
| 109 | |
| 110 | select by numbers:: |
| 111 | |
| 112 | This shows the files and directories to be deleted and issues an |
| 113 | "Select items to delete>>" prompt. When the prompt ends with double |
| 114 | '>>' like this, you can make more than one selection, concatenated |
| 115 | with whitespace or comma. Also you can say ranges. E.g. "2-5 7,9" |
| 116 | to choose 2,3,4,5,7,9 from the list. If the second number in a |
Jiang Xin | 309422e | 2013-07-24 06:22:43 +0800 | [diff] [blame] | 117 | range is omitted, all remaining items are selected. E.g. "7-" to |
Jiang Xin | c0be6b4 | 2013-06-25 23:53:55 +0800 | [diff] [blame] | 118 | choose 7,8,9 from the list. You can say '*' to choose everything. |
| 119 | Also when you are satisfied with the filtered result, press ENTER |
| 120 | (empty) back to the main menu. |
| 121 | |
| 122 | ask each:: |
| 123 | |
| 124 | This will start to clean, and you must confirm one by one in order |
| 125 | to delete items. Please note that this action is not as efficient |
| 126 | as the above two actions. |
| 127 | |
| 128 | quit:: |
| 129 | |
| 130 | This lets you quit without do cleaning. |
| 131 | |
| 132 | help:: |
| 133 | |
| 134 | Show brief usage of interactive git-clean. |
| 135 | |
Philip Oakley | 068c674 | 2012-09-19 00:25:33 +0100 | [diff] [blame] | 136 | SEE ALSO |
| 137 | -------- |
| 138 | linkgit:gitignore[5] |
| 139 | |
Pavel Roskin | c3b831b | 2006-04-05 02:00:48 -0400 | [diff] [blame] | 140 | GIT |
| 141 | --- |
Christian Couder | 9e1f0a8 | 2008-06-06 09:07:32 +0200 | [diff] [blame] | 142 | Part of the linkgit:git[1] suite |