简体   繁体   English

Git忽略并取消跟踪文件[是的,我已经阅读了其他帖子]

[英]Git ignore and untrack file [Yes I already readed the other posts]

I put some folders in my gitignore but as described in the documentation 我在gitignore中放入了一些文件夹,但如文档所述

A gitignore file specifies intentionally untracked files that Git should ignore. gitignore文件指定Git应该忽略的故意未跟踪的文件。 Files already tracked by Git are not affected 已被Git跟踪的文件不受影响

So I have to untrack some files and is where my nightmare start 所以我必须取消跟踪某些文件,这是我噩梦开始的地方

This is my gitignore file 这是我的gitignore文件

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

The last modification made in this file was the addition of the line /images/* 此文件中的最后一个修改是添加了/ images / *行

To untrack this folder i follow as described {1} here and {2} here 到untrack此夹i遵循所描述的{1} 这里和{2} 在这里

Following {1} 跟随{1}

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

Question 1: Why can't untrack this specific file? 问题1:为什么无法取消跟踪此特定文件?

Following {2} 跟随{2}

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

Same result with specific file 特定文件的结果相同

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

Question 2: Why I receive this error message? 问题2:为什么我会收到此错误消息? Searching here lead me to this but, as I said, these files under /images/ are tracked. 在这里搜索使我想到了这一点,但是,正如我所说的,/ images /下的这些文件已被跟踪。

And the Cake Cherry 还有蛋糕樱桃

To verify the list of ignored file I ran this command 为了验证被忽略文件的列表,我运行了此命令

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

That give me a very long list of files inside the images, administrator and mpdf61 folder. 那给了我很长的图像,管理员和mpdf61文件夹中的文件列表。 The mpdf61 folder is not configured in the gitignore file and neither in info/exclude. 未在gitignore文件中配置mpdf61文件夹,在info / exclude中也未配置。

Question 3: Why the mpdf61 appears in this list?

Note: "tracked" means "in the index". 注意:“ tracked”的意思是“在索引中”。 "Untracked" means "not in the index". “未跟踪”表示“不在索引中”。 The display of a files untracked-ness is normally suppressed if it's also ignored, so some prefer to call files whose state is "both untracked and ignored" just "ignored", quietly glossing over their "untracked"-ness. 如果也忽略了文件未跟踪状态的显示,通常会抑制它们的显示,因此有些人更喜欢将状态为“未跟踪和已忽略”的文件称为“已忽略”,从而悄悄地掩盖其“未跟踪”状态。 Note that the index need not match the current HEAD commit: that's how you prepare the next commit, by making changes to the index. 请注意,索引不必与当前的HEAD提交匹配:这是通过对索引进行更改来准备下一次提交的方式。 Those changes become part of a permanent commit only once you make the commit, and the act of making that commit updates HEAD as well. 仅当您进行提交后,这些更改才成为永久提交的一部分,并且进行该提交的操作也会更新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? 问题1:为什么无法取消跟踪此特定文件?

You can't untrack it because it's not tracked. 您无法取消跟踪,因为它没有被跟踪。 Moreover, git update-index --assume-unchanged does not untrack a file in the first place. 此外, git update-index --assume-unchanged不会取消跟踪文件。 For update-index to update the "assume unchanged" bit, the file must be in the index, so that update-index has something to update. 为了使update-index更新“假定不变”位,文件必须在索引中,以便update-index有要更新的内容。 This fatal error occurs with the first such untracked (not-in-the-index) file. fatal错误发生在第一个此类未跟踪(不在索引中)文件中。 Nothing else happens to any of the subsequent files named by the shell's expansion of * , as update-index just stops after the first error. 由shell的*扩展名命名的任何后续文件都没有发生任何变化,因为update-index在第一个错误发生后才停止。

(For instance, if you run git update-index --assume-unchanged red.txt blue.jpg green.svg , and both red.txt and green.svg are in the index while blue.jpg is not in the index, update-index will mark the index entry for red.txt but not the one for green.svg .) (例如,如果你运行git update-index --assume-unchanged red.txt blue.jpg green.svg ,都red.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 

Question 2: Why I receive this error message? 问题2:为什么我会收到此错误消息?

Because that file is also not tracked (not in the index) and therefore cannot be removed from the index. 因为该文件也不会被跟踪(不在索引中),因此无法从索引中删除。 This: 这个:

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

means that no images/ files are (now) in the index. 表示索引中没有 (现在) images/文件。 (Perhaps some were before, and are therefore in the HEAD commit, but no longer are, after an earlier successful git rm --cached ; if so, they should show up in git status as "deleted".) (也许有些在以前,因此在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. 那给了我很长的图像,管理员和mpdf61文件夹中的文件列表。 The mpdf61 folder is not configured in the gitignore file and neither in info/exclude. 未在gitignore文件中配置mpdf61文件夹,在info / exclude中也未配置。

Question 3: Why the mpdf61 appears in this list? 问题3:为什么mpdf61出现在此列表中?

Presumably because those file are ignored. 大概是因为那些文件被忽略了。 There are three "standard" exclusion file classes, as shown in the git ls-files documentation: 共有三个“标准”排除文件类,如git ls-files文档所示:

--exclude-standard
Add the standard Git exclusions: .git/info/exclude, .gitignore in each directory, and the user's global exclusion file . 添加标准的Git排除项:.git / info / exclude, 每个目录中的 .gitignore 以及用户的全局排除文件

(all emphasis mine). (所有重点都是我的)。 You said "the" (as in one) gitignore file, but there may be many, including one within the directory mpdf61 itself, and you may have a core.excludesFile configured. 您说的是“(一个)” gitignore文件,但可能有很多,包括mpdf61本身的目录中的一个,并且可能已配置了core.excludesFile

To find which ignore directive is ignoring a specific file, use git check-ignore -v . 要查找哪个忽略指令忽略了特定文件,请使用git check-ignore -v See the git check-ignore documentation . 请参阅git check-ignore文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM