Git忽略和未跟踪文件[是的我已经读过其他帖子]

时间:2016-12-16 20:15:27

标签: linux git gitignore git-untracked

我在我的gitignore中放了一些文件夹,但正如documentation

中所述
  

gitignore文件指定Git应忽略的故意未跟踪文件。 Git已经跟踪的文件不受影响

所以我必须解开一些文件,这是我的噩梦开始的地方

这是我的gitignore文件

@Override
public long getItemId(int position) {
    return position;
}

@Override
public int getItemViewType(int position) {
   return position;
}

此文件中的最后一次修改是添加了行/ images / *

要按照{1} here和{2} here

所述的方式取消跟踪此文件夹

关注{1}

$ cat .gitignore
/.settings/
/.buildpath
/configuration.php
/administrator/cache/*
/images/*
/connectionOracle.php
/administrator/components/com_jsecure/*
/administrator/language/en-GB/*

问题1:为什么不能解开这个特定文件?

关注{2}

$ git update-index --assume-unchanged images/*
fatal: Unable to mark file images/02102012_planos.jpg

与特定文件相同的结果

$ git rm --cached images/ -r
fatal: pathspec 'images' did not match any files

问题2:为什么我收到此错误消息?在这里搜索引导我this,但正如我所说,跟踪/ images /下的这些文件。

蛋糕樱桃

要验证已忽略文件的列表,我运行了此命令

$ git rm --cached images/20130626tabela1.jpg
fatal: pathspec 'images/20130626tabela1.jpg' did not match any files

这给了我一个很长的文件列表,包括图片,管理员和mpdf61文件夹。      mpitf文件夹未在gitignore文件中配置,也未在info / exclude中配置。

$git ls-files --others -i --exclude-standard

1 个答案:

答案 0 :(得分:2)

注意:“跟踪”表示“在索引中”。 “未跟踪”表示“不在索引中”。如果文件未被跟踪,则通常会禁止显示未跟踪的文件,因此有些人更喜欢调用其状态为“未跟踪且被忽略”而刚被“忽略”的文件,静静地掩盖其“未跟踪”的性质。请注意,索引不需要与当前HEAD提交匹配:这是您通过更改索引来准备下一个提交的方式。只有在您提交后,这些更改才会成为永久提交的一部分,并且提交该提交的行为也会更新HEAD

$ git update-index --assume-unchanged images/*
fatal: Unable to mark file images/02102012_planos.jpg
     

问题1:为什么不能解开这个特定文件?

你无法解开它,因为它没有被跟踪。此外,git update-index --assume-unchanged首先不会删除文件。要使update-index更新“假定未更改”位,文件必须位于索引中,以便update-index有更新内容。第一个此类未跟踪(非索引)文件发生此fatal错误。 shell的扩展*命名的任何后续文件都没有发生任何其他事件,因为update-index在第一次错误后停止。

(例如,如果您运行git update-index --assume-unchanged red.txt blue.jpg green.svgred.txtgreen.svg 都在中,而blue.jpg在索引中update-index将标记red.txt的索引条目,而不是green.svg的索引条目。)

$ git rm --cached images/20130626tabela1.jpg
fatal: pathspec 'images/20130626tabela1.jpg' did not match any files
     

问题2:为什么我收到此错误消息?

因为该文件也未被跟踪(不在索引中),因此无法从索引中删除。这样:

$ git rm --cached images/ -r
fatal: pathspec 'images' did not match any files

表示没有 images/文件(现在)在索引中。 (也许有些人在之前,因此在HEAD提交之后,但在早先成功git rm --cached之后不再是;如果是这样,他们应该在git status中显示为“已删除” 。)

$ git ls-files --others -i --exclude-standard
     

这给了我一个很长的文件列表,包括图片,管理员和mpdf61文件夹。没有在gitignore文件中配置mpdf61文件夹,也没有在info / exclude中配置。

     

问题3:为什么mpdf61出现在这个列表中?

大概是因为那些文件被忽略了。有三个“标准”排除文件类,如git ls-files文档中所示:

  

--exclude-standard
  在每个目录中添加标准Git排除项:.git / info / exclude,.gitignore 用户的全局排除文件

(所有强调我的)。你说的是“那个”(如同一个)gitignore文件,但可能有很多,包括目录mpdf61内的一个,你可能配置了core.excludesFile

要查找忽略特定文件的ignore指令,请使用git check-ignore -v。请参阅the git check-ignore documentation

相关问题