mkdir repo
cd repo
git init
mkdir temp
touch temp/in.tmp
touch out.tmp
echo '*tmp' > .gitignore
when use git clean -Xn
it show Would remove out.tmp
but I want to remove temp/in.tmp
together
git clean -Xdn
not work too, but cd
to temp
directory and run git clean -Xn
it show Would remove in.tmp
so I wonder is there a command to remove all file list in .gitignore
include subdirectory, in this case how to use git clean
remove temp/in.tmp
and out.tmp
$ git --version
git version 1.9.5.msysgit.1
I found something weird
add a file in temp
directory and stage it , git clean -Xn
seems work
touch temp/a.txt
git add temp/a.txt
git clean -Xn
it show
Would remove out.tmp
Would remove temp/in.tmp
but why that happend ?
git clean -X will remove any files matching the patterns in . gitignore . The -n at the end causes it to not actually remove files, only to dry run, reporting files that would have been removed. Add -d to also remove ignored directories.
gitignore are not being tracked, you can use the git clean command to recursively remove files that are not under version control. Use git clean -xdn to perform a dry run and see what will be removed. Then use git clean -xdf to execute it. Basically, git clean -h or man git-clean (in unix) will give you help.
You need -x
because you want to delete file ignored by .gitignore
git clean -fdx
will successufully clean everything for you
macsp:repo proto$ git clean -fdxn
Would remove .gitignore
Would remove out.tmp
Would remove temp/
macsp:repo proto$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With