2012-07-10 148 views
1

當我克隆advimage存儲庫時,img/目錄似乎未被跟蹤。在github存儲庫中的未跟蹤目錄中跟蹤文件

[email protected] advimage % git st 
?? img/ 
[email protected] advimage % git status 
# On branch develop 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# img/ 
nothing added to commit but untracked files present (use "git add" to track) 

這個目錄是不是空的,還有的跟蹤在img/命名sample.gif文件。我嘗試添加 一個空文件:

[email protected] advimage % touch img/hede 
[email protected] advimage % git add img/hede 
[email protected] advimage % git st 
A img/hede 
?? img/ 
[email protected] advimage % rm -rf img 
[email protected] advimage % git st 
AD img/hede 
D img/sample.gif 
[email protected] advimage % git reset 
Unstaged changes after reset: 
M img/sample.gif 
[email protected] advimage % git st 
D img/sample.gif 
[email protected] advimage % 

git fsck --full輸出是空的。爲什麼我不能在git status列表中刪除img/

+0

嘿,我的git版本比版本庫服務器git更舊。 – gokmen 2012-09-05 14:06:03

回答

2

您從文件系統中刪除了這些文件,但是您沒有將它們從存儲庫的索引中刪除。發出git rm -r img/ && git commit完全刪除img/目錄。

發生了什麼事:

[email protected] advimage % rm -rf img 
[email protected] advimage % git st 
AD img/hede 
D img/sample.gif 

AD img/hede建議您COMMITED新文件img/hede,然後刪除了它,而無需使用git rmD img/sample.gif建議您刪除img/sample.gif而不使用git rm

[email protected] advimage % git reset 
Unstaged changes after reset: 
M img/sample.gif 

git reset意味着混帳停止跟蹤img/hede,這是未提交併通過rm -rf命令刪除。 img/sample.gif仍然從之前的跟蹤(和修改)。如果你發出git reset --hard,你會在這裏看到沒有輸出,但是img/sample.gif會回到工作目錄。

[email protected] advimage % git st 
D img/sample.gif 

這說明你rm代替git rm刪除img/sample.gif。此時,您可以發出git rm img/sample.gif && git commit刪除文件。

+0

感謝您的答案,但我不想刪除img目錄和它的文件,我只想隱藏'img /'從'git status'輸出。 sample.gif是我需要的。 – gokmen 2012-07-10 12:52:15

+0

在命令系列結束時,當'status'只返回'D img/sample.gif'時,嘗試發出'git reset --hard',然後'git status'。這將丟棄未提交的工作,所以如果你有其他文件躺在附近,先運行'git stash'。 – Christopher 2012-07-10 12:58:22