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?
The git clean command also allows removing ignored files and directories.
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/* ).
Use your favorite text editor to open the file called . git/info/exclude within the root of your Git repository. Any rule you add here will not be checked in, and will only ignore files for your local repository.
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.
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