"git clean -f" does not leave an empty directory

If I have a directory application in my repository with a single, raw file in it and I run git clean -f , I get the message: Do not delete the application / and the non-screen file is still there.

But if I have an additional, tracked file in the same directory, and I execute the same command, then the file without a trace is deleted successfully.

So my question is: why does Git try to delete the directory if it is empty after cleaning it from raw files?

Below is a script that reproduces the behavior. Thanks in advance.

 #!/bin/bash # Create new empty repo mkdir myrepo && cd myrepo git init # Create app directory with main.c mkdir app touch app/main.c # Try to delete main.c with git clean -> Not working git clean -f # Add helper.c to app directory and add to index touch app/helper.c git add app/helper.c # Try to delete main.c with git clean -> Now it working git clean -f 
+6
source share
2 answers

You need to pass the -d to git clean to remove non-displayable directories.

+7
source

git does not track directories - you cannot pass an empty git directory.

(try creating an empty directory and adding it to git - you will not see changes in git status)

Even if you add some files to an unsigned directory, git will not show you all the files in git status - it will just show the directory

Check this question for more answers on why git does not support version directories.

So, as @Hasturkun pointed out in his answer, you need to pass -d to git clean to remove unprepared directories

+3
source

Source: https://habr.com/ru/post/952927/


All Articles