为什么 git clean -f 不删除所有未跟踪的文件?

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

我今天打了这个:

% 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

好的,我将删除未跟踪的文件:

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

但是,似乎并非所有未跟踪的文件都已删除:

% 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

奇怪的是,起初 git checkout another_branch git 知道它后来抱怨的那些特定的未跟踪文件(alembic/READMEalembic/env.pyalembic/script.py.mako) .

那么为什么 git 没有删除它们?

目录是否包含 .git 个子目录或文件?

-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.

有两种未跟踪文件:未跟踪文件和忽略文件。

当 运行 为 git clean-f 只是覆盖 "safety" 配置选项)时,git 将仅删除未跟踪的文件,当 运行 as git clean -x 它将删除未跟踪和忽略的文件。

checkout问题,可能是两个分支的.gitignore个文件不同引起的