When I have .gitignore data/*
and run git clean -fd
, the data folder and all its content files are deleted.
What I want is to delete all unrevisioned files in a git repo while excluding all ignored files (i.e. DON'T delete gitignored files). What could I do?
Git normally don't clean ignored files unless you specify the -x
flag, but strangely it cleans out when configured as you did (folder/*
).
As @VonC commented it out, you should change your .gitignore
to ignore the directory (data/
) rather than what's in it (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.