If I have a directory app in my repository with a single, untracked file in it and I execute git clean -f
, I get the message: Not removing app/ and the untracked file is still there.
But if I have an additional, tracked file within the same directory and I execute the exact same command then the untracked file is removed successfully.
So my question is: Why is Git trying to delete the directory if it would be empty after cleaning it from untracked files?
Below is a script which 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's working
git clean -f