Skip to content

Commit ced002e

Browse files
committed
Add 'git sparse-checkout clean' (#779)
This is a fast-track of gitgitgadget#1941, so please see that PR for the full context and details. This is being prioritized as it solves a pain point for Office monorepo developers who get stuck with files outside of their sparse-checkout but no clear guidance as to how to solve the problem. With this change, users are advised to run `git sparse-checkout clean` as a heavy hammer to get into a better state. This will make their sparse index work as intended instead of slowing them down more than they should. The upstream version got stuck on some minor details that may lead to an adjusted CLI. However, it got blocked on a dependent change due to globals refactoring. This is marked experimental for now.
2 parents a9718b4 + 8abc09c commit ced002e

File tree

7 files changed

+374
-58
lines changed

7 files changed

+374
-58
lines changed

Documentation/git-sparse-checkout.adoc

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-sparse-checkout - Reduce your working tree to a subset of tracked files
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git sparse-checkout' (init | list | set | add | reapply | disable | check-rules) [<options>]
12+
'git sparse-checkout' (init | list | set | add | reapply | disable | check-rules | clean) [<options>]
1313

1414

1515
DESCRIPTION
@@ -111,6 +111,29 @@ flags, with the same meaning as the flags from the `set` command, in order
111111
to change which sparsity mode you are using without needing to also respecify
112112
all sparsity paths.
113113

114+
'clean'::
115+
Remove all files in tracked directories that are outside of the
116+
sparse-checkout definition. This subcommand requires cone-mode
117+
sparse-checkout to be sure that we know which directories are
118+
both tracked and all contained paths are not in the sparse-checkout.
119+
This command can be used to be sure the sparse index works
120+
efficiently, though it does not require enabling the sparse index
121+
feature via the `index.sparse=true` configuration.
122+
+
123+
To prevent accidental deletion of worktree files, the `clean` subcommand
124+
will not delete any files without the `-f` or `--force` option, unless
125+
the `clean.requireForce` config option is set to `false`.
126+
+
127+
The `--dry-run` option will list the directories that would be removed
128+
without deleting them. Running in this mode can be helpful to predict the
129+
behavior of the clean comand or to determine which kinds of files are left
130+
in the sparse directories.
131+
+
132+
The `--verbose` option will list every file within the directories that
133+
are considered for removal. This option is helpful to determine if those
134+
files are actually important or perhaps to explain why the directory is
135+
still present despite the current sparse-checkout.
136+
114137
'disable'::
115138
Disable the `core.sparseCheckout` config setting, and restore the
116139
working directory to include all files.

0 commit comments

Comments
 (0)