Git 2 reference · Undoing Changes
git clean Command (Git)
Remove untracked files from the working tree; always preview with -n first.
Git 2
Syntax
git clean -n|-f [-d] [-x]
Parameters
| Parameter | Description |
|---|---|
-n |
Dry run: show what would be removed. |
-f |
Actually remove. |
-d |
Include directories. |
-x |
Also remove ignored files. |
Examples
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
mkdir build; touch build/app.o tmp.log
git clean -n -d
Output
Would remove build/ Would remove tmp.log
Run this on your computer — see “Get Started” for setup.
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
echo '*.log' > .gitignore; git add .gitignore; git commit -q -m ignore
touch a.tmp debug.log
git clean -f -q; ls
git clean -f -x -q; ls
Output
README.md debug.log README.md
Run this on your computer — see “Get Started” for setup.
Related
git restore· Discard working-tree changes to files, or unstage files, without touching other work.git check-ignore· Find out whether a path is ignored and which .gitignore rule ignores it; useful for debugging .gitignore patterns.- Undoing Changes · tutorial