How to preserve all ignored files in git clean -fd?
Git normally doesn't clean ignored files unless the -x
flag is specified, but strangely it cleans out when configured as you did (folder/*
).
As @VonC pointed out, you should change your .gitignore
-file to ignore the directory (data/
) rather than its contents (data/*
).
It's a subtle difference, but it matters to git.
I've found some more details. Having /tmp/*
in gitignore, git clean -fd
will remove it. As it was said in other answers, this does not happens with /tmp/
in gitignore.
But once you have any checked-in any file in this directory, git clean -fd
will ignore this path. This can be achieved with git add -f
or adding !/tmp/.keep
to gitignore and checking this file in.