2014-01-27 53 views
0

我剛剛更新了我的.gitignore文件,不包含節點和涼亭模塊文件。爲什麼git刪除我的腳本文件夾?

node_modules/ 
.tmp 
.sass-cache 
sample/bower_components/ 
sample/node_modules/ 
sample/images/ 

但是當我運行git clean -f,我的終端與

Removing sample/scripts 
當然

迴應,該sample/scripts是我要保持項目的文件夾,我沒有指定它.gitignore,爲什麼它被刪除?

+0

問一個很明顯的問題,是否已將'sample/scripts'添加到git倉庫中? – agmin

+0

因爲'sample/scripts'不受版本控制? –

+0

它是一個空目錄嗎? [Git不跟蹤空目錄。](http://stackoverflow.com/questions/115983/how-do-i-add-an-empty-directory-to-a-git-repository) –

回答

4

git clean會刪除不知道Git的文件。如果您沒有通過-x標誌,它將刪除未被跟蹤但未明確忽略的文件。

因此,如果sample/scripts被刪除,那麼它顯然不被Git跟蹤。如果你想保留它,你必須通過添加並委託它來追蹤它,或者將它添加到.gitignore

Btw。首先運行git clean -n是個好主意,以便在實際執行此操作之前查看Git將刪除的內容。

+0

對於' -x'和'-n'標誌。 – Sam

0

我假設你沒有從sample/scripts目錄中添加任何文件到Git存儲庫。這意味着他們是不被跟蹤,並從git-clean手冊,他們將被刪除:Cleans the working tree by recursively removing files that are not under version control, starting from the current directory.

您可以查看哪些文件正在由本地資源庫與追蹤:

git ls-tree --full-tree -r HEAD 

如果文件丟失,只需添加他們:

git add sample/scripts/. 
git commit -m "Add missing sample scripts" 
git clean -f 

Git只是跟蹤文件,所以空白目錄將不會計數。您可以添加一個基本的.gitignore解決這個問題:

touch sample/scripts/.gitignore 
git add sample/scripts/.gitignore 
git commit -m "Add sample scripts gitignore" 
git clean -f 
相關問題