我在我的 gitignore 中放置了一些文件夹,但如 documentation 中所述
A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected
所以我必须取消跟踪一些文件,这就是我的噩梦开始的地方
这是我的 gitignore 文件
$ cat .gitignore
/.settings/
/.buildpath
/configuration.php
/administrator/cache/*
/images/*
/connectionOracle.php
/administrator/components/com_jsecure/*
/administrator/language/en-GB/*
此文件中的最后修改是添加行/images/*
要取消跟踪此文件夹,我按照说明进行操作 {1} here和{2} here
关注 {1}
$ git update-index --assume-unchanged images/*
fatal: Unable to mark file images/02102012_planos.jpg
问题 1:为什么无法取消跟踪此特定文件?
关注{2}
$ git rm --cached images/ -r
fatal: pathspec 'images' did not match any files
与特定文件相同的结果
$ git rm --cached images/20130626tabela1.jpg
fatal: pathspec 'images/20130626tabela1.jpg' did not match any files
问题 2:为什么我会收到此错误消息?在此处搜索会将我带到 this但是,正如我所说,/images/下的这些文件已被跟踪。
还有蛋糕樱桃
为了验证忽略文件的列表,我运行了这个命令
$git ls-files --others -i --exclude-standard
这给了我图像、管理员和 mpdf61 文件夹中的一长串文件。 mpdf61 文件夹未在 gitignore 文件中配置,也未在 info/exclude 中配置。
Question 3: Why the mpdf61 appears in this list?
最佳答案
注意:“跟踪”的意思是“在索引中”。 “未跟踪”意味着“不在索引中”。如果文件也被忽略,则未跟踪文件的显示通常会被抑制,因此有些人更喜欢将状态为“既未跟踪又被忽略”的文件称为“忽略”,悄悄地掩饰它们的“未跟踪”状态。请注意,索引不需要匹配当前的 HEAD
提交:这就是您通过更改索引来准备下一个 提交的方式。只有在您进行提交后,这些更改才会成为永久提交的一部分,并且进行该提交的行为也会更新 HEAD
。
$ git update-index --assume-unchanged images/* fatal: Unable to mark file images/02102012_planos.jpg
Question 1: Why can't untrack this specific file?
您无法取消跟踪它,因为它未被跟踪。此外,git update-index --assume-unchanged
不会首先取消跟踪文件。要使 update-index
更新“假设未更改”位,文件必须在索引中,这样 update-index
才能更新某些内容。此 fatal
错误发生在第一个此类未跟踪(不在索引中)文件中。由 shell 扩展 *
命名的任何后续文件都不会发生任何其他情况,因为 update-index
在第一个错误后停止。
(例如,如果您运行 git update-index --assume-unchanged red.txt blue.jpg green.svg
,red.txt
和 green.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
Question 2: Why I receive this error message?
因为该文件也未被跟踪(不在索引中),因此无法从索引中删除。这:
$ 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
That give me a very long list of files inside the images, administrator and mpdf61 folder. The mpdf61 folder is not configured in the gitignore file and neither in info/exclude.
Question 3: Why the mpdf61 appears in this list?
大概是因为那些文件被忽略了。如 git ls-files
文档中所示,共有三个“标准”排除文件类:
--exclude-standard
Add the standard Git exclusions: .git/info/exclude, .gitignore in each directory, and the user's global exclusion file.
(所有强调我的)。你说的是“the”(在一个)gitignore 文件,但可能有很多,包括目录 mpdf61
本身中的一个,你可能配置了一个 core.excludesFile
.
要查找忽略特定文件的忽略指令,请使用 git check-ignore -v
。参见 the git check-ignore
documentation .
关于linux - Git 忽略并取消跟踪文件 [是的,我已经阅读了其他帖子],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41191837/