According to the help, without -x
option git clean
should let alone the ignored files, but it doesn't.
[il@reallin test]$ cat .gitignore
*.sar
[il@reallin test]$ mkdir -p conf/sar && touch conf/sar/aaa.sar
[il@reallin test]$ git status
# On branch master
nothing to commit, working directory clean
[il@reallin test]$ git clean -df
Removing conf/
conf/sar/aaa.sar
is removed. Is it a bug?
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/* ).
git clean deletes ignored files only if you use either the -x or -X option, otherwise it just deletes untracked files.
According to man git clean
:
-d
Remove untracked directories in addition to untracked files.
In your case, directory conf/sar
is not tracked - it does not contain any files that are tracked by git. If you did not have gitignore rule and executed git clean -fd
, contents of this untracked directory would have been removed - just what documentation says.
Now, if you add .gitignore
with rule to ignore *.sar
files, it does not change basic fact that your directory conf/sar/
is still untracked, and having untracked file aaa.sar that is eligible for this gitignore rule should not suddenly make it unremovable by git clean -fd
.
But, if you add any tracking file next to your ignored aaa.sar
, then this directory would not be removed and your file will be left alone.
In other words, while it looks confusing, this is not a bug and git does exactly what documentation says.
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