Git is ignoring files that aren't in gitignore
I have a git repository that is ignoring image files as well as a few other files, but my .gitignore
file only has it ignoring a config.php
file. Is there some global ignore file somewhere that I can't seem to find? I have to specify files to add them now, and it's giving me this warning:
The following paths are ignored by one of your .gitignore files.
The contents of my ~/.gitconfig
file are only my e-mail address.
Solution 1:
git check-ignore
Use git check-ignore
command to debug your gitignore file (exclude files).
For 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 HOME and repository folder:
cat ~/.gitignore "$(git rev-parse --show-toplevel)"/.gitignore "$(git rev-parse --show-toplevel)"/.git/info/exclude
Alternatively use git add -f
which allows adding otherwise ignored files.
See: man gitignore
, man git-check-ignore
for more details.
Syntax
git check-ignore [options] pathname…
git check-ignore [options] --stdin
Solution 2:
It might be good to know that your git configuration can contain a core.excludesfile which is a path to a file with additional patterns that are ignored. You can find out if you have such a configuration by running (in the problematic git repo):
git config core.excludesfile
If it prints a file path, look at the contents of that file for further information.
In my case I installed git via an old version of boxen which ignored the pattern 'Icon?' that in my case gave me the warning, mentioned in this question, for a folder icons (I'm on a case insensitive filesystem that's why Icon? matches icons).
Solution 3:
Check these out:
Have you looked for other .gitignore files, as there can be many of them.
Also, look at REPO/.git/config to see if there is anything there.
Repo exclude Local per-repo rules can be added to the .git/info/exclude file in your repo. These rules are not committed with the repo so they are not shared with others. This method can be used for locally-generated files that you don’t expect other users to generate, like files created by your editor.
Solution 4:
I had the same problem - a directory was being ignored by git with this error:
➭ git add app/views/admin/tags/
The following paths are ignored by one of your .gitignore files:
app/views/admin/tags
Use -f if you really want to add them.
fatal: no files added
I finally figured out my problem was a line in my ~/.gitignore_global
:
TAGS
which was matching the path app/views/admin/tags
. I fixed it by adding a leading slash to the global gitignore file
/TAGS
and git started tracking my directory again.
Solution 5:
For me I accidentally had a wildcard in my ~/.gitignore_global file. Maybe check there?