grgit-clean
Synopsis
grgit.clean()
grgit.clean(paths: ['<path>', ...], directories: <boolean>, dryRun: <boolean>, ignore: <boolean>)
grgit.clean {
paths = ['<path>', ...]
directories = <boolean>
dryRun = <boolean>
ignore = <boolean>
}
Description
Cleans the working tree by removing files that are not under version control.
Normally, only files uknown to Git are removed, but if ignore
is false
, ignored files are also removed. This can, for example, be useful to remove all build products.
If any optional paths
are given, only those paths are affected.
Returns a Set<String>
of the paths that were deleted.
Options
- directories
-
(
boolean
, defaultfalse
) Remove untracked directories in addition to untracked files. - dryRun
-
(
boolean
, defaultfalse
) Don’t actually remove anything, just show what would be done. - ignore
-
(
boolean
, defaulttrue
) Don’t use the standard ignore rules read from .gitignore (per directory) and $GIT_DIR/info/exclude. This allows removing all untracked files, including build products. This can be used (possibly in conjunction with git reset) to create a pristine working directory to test a clean build. - paths
-
(
Set<String>
, defaultnull
) Only remove files in the given paths.
Examples
To clean all untracked files, but not ignored ones or untracked directories.
def cleanedPaths = grgit.clean()
To clean all untracked files and directories.
def cleanedPaths = grgit.clean(directories: true)
To clean all untracked files, including ignored ones.
def cleanedPaths = grgit.clean(ignore: false)
To only return files that would be cleaned.
def cleanedPaths = grgit.clean(dryRun: true)
To clean specific untracked files.
def cleanedPaths = grgit.clean(paths: ['specific/file.txt'])