2015-11-05 111 views
0

我今天这样打:为什么git clean -f不会删除所有未跟踪的文件?

% 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,所以我会删除未跟踪文件:

% 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/README,alembic/env.pyalembic/script.py.mako)。

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

回答

1

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

当运行为git clean-f只是覆盖“安全”配置选项),git会只git clean -x运行时,删除未跟踪文件,它会删除这两个未跟踪或忽略的文件。

对于结帐问题,它可能是由两个分支中的不同.gitignore文件触发的。

0

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

-f,--force

如果Git的配置变量clean.requireForce未设置为false,混帐 干净将拒绝删除文件或目录,除非给出-f,-n或-i 。 Git 将拒绝使用.git子目录或文件删除目录,除非给出第二个 -f。这也会影响到git子模块,其中在-f被赋予两次之前,不会删除在.git/modules /下的 子模块的存储区域。

相关问题