2012-07-10 89 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

相关问题