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

410 views Asked by At

I put some folders in my gitignore but as described in the documentation

A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected

So I have to untrack some files and is where my nightmare start

This is my gitignore file

$ 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/*

To untrack this folder i follow as described {1}here and {2}here

Following {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?

Following {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? Searching here lead me to this but, as I said, these files under /images/ are tracked.

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. The mpdf61 folder is not configured in the gitignore file and neither in info/exclude.

Question 3: Why the mpdf61 appears in this list?
1

There are 1 answers

0
torek On BEST ANSWER

Note: "tracked" means "in the index". "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. 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.


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

Question 1: Why can't untrack this specific file?

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. For update-index to update the "assume unchanged" bit, the file must be in the index, so that update-index has something to update. This fatal error occurs with the first such untracked (not-in-the-index) file. 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.

(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 rm --cached images/20130626tabela1.jpg
fatal: pathspec 'images/20130626tabela1.jpg' did not match any files

Question 2: Why I receive this error message?

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. (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".)


$ 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?

Presumably because those file are ignored. There are three "standard" exclusion file classes, as shown in the git ls-files documentation:

--exclude-standard
       Add the standard Git exclusions: .git/info/exclude, .gitignore in each directory, and the user's global exclusion file.

(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.

To find which ignore directive is ignoring a specific file, use git check-ignore -v. See the git check-ignore documentation.