Git is not detecting a file and is not in .gitignore

Another note, probably a rare case but I had this problem. I moved some files that were already tied to a repo from one directory to another, copy/paste style.

Along with it came the .git folder, which prevented git from detecting the folder.

So my folder structure was this, with git not detecting Folder 2 even though the repo was set for Original Project 1:

--Original Project 1
    --.git
    --Folder 1
    --Folder 2
         --.git
         --Many other files/folders

Deleting the child .git folder solved my problem.


The file could also be listed in .git/info/exclude, and there’s the option core.excludesfile to watch, too.


Use git check-ignore command to debug your gitignore file (exclude files).

In example:

$ git check-ignore -v config.php
.gitignore:2:src    config.php

The above output details about the matching pattern (if any) for each given pathname (including line).

So maybe your file extension is not ignored, but the whole directory.

The returned format is:

<source> <COLON> <linenum> <COLON> <pattern> <HT> <pathname>

Or use the following command to print your .gitignore in user and repo folder:

cat ~/.gitignore $(git rev-parse --show-toplevel)/.gitignore $(git rev-parse --show-toplevel)/.git/info/exclude

Alternatively use git add -f <path/file> which allows adding otherwise ignored files.

See: man gitignore, man git-check-ignore for more details.

Tags:

Git