LetMeSOThat4U
LetMeSOThat4U

Reputation: 6758

Why git clean -f does not remove all the untracked files?

I hit this today:

% git checkout another_branch
error: The following untracked working tree files would be overwritten by checkout:
        __version__.txt
        alembic.ini
        alembic/README
        alembic/env.py
        alembic/script.py.mako
        folder1/file1
        folder2/file2
        ....
Please move or remove them before you can switch branches.
Aborting

OK, so I'll remove untracked files:

% git clean -f
Not removing alembic/
Not removing tools/maintenance/

However, it seems that not all untracked files have been removed:

% git checkout another_branch
error: The following untracked working tree files would be overwritten by checkout:
        alembic/README
        alembic/env.py
        alembic/script.py.mako
Please move or remove them before you can switch branches.
Aborting

What's weird is that at first git checkout another_branch git knew about those particular untracked files it later complained about (alembic/README, alembic/env.py, alembic/script.py.mako).

So why git did not delete them?

Upvotes: 3

Views: 3473

Answers (2)

giosh94mhz
giosh94mhz

Reputation: 3066

There are two kind of untracked files: untracked files and ignored files.

When running as git clean (-f is just to override a "safety" config option), git will only remove untracked files, when running as git clean -x it will remove both untracked and ignored files.

For the checkout issue, it is probably triggered by different .gitignore files in the two branches.

Upvotes: 1

choroba
choroba

Reputation: 241858

Do the directories contain .git subdirectories or files?

-f, --force

If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to delete files or directories unless given -f, -n or -i. Git will refuse to delete directories with .git sub directory or file unless a second -f is given. This affects also git submodules where the storage area of the removed submodule under .git/modules/ is not removed until -f is given twice.

Upvotes: 2

Related Questions