2015-11-05 115 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 /下的 子模塊的存儲區域。

相關問題