Git is ignoring files that aren't in gitignore

2020-01-24 20:09发布

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.

标签: git gitignore
13条回答
仙女界的扛把子
2楼-- · 2020-01-24 20:23

Make sure the .gitignore file is not ignoring itself. A common mistake is adding a * rule to the .gitignore file to ignore every file in the current folder. The solution to this is to add an exception to .gitignore:

*
!.gitignore

This way all files in the directory will be ignored, except .gitignore.

查看更多
够拽才男人
3楼-- · 2020-01-24 20:24

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

查看更多
Ridiculous、
4楼-- · 2020-01-24 20:25

Please also check ~/.gitignore and ~/.gitignore_global which might be created by some Git clients (e.g. Atlassian SourceTree on Mac OS X).

查看更多
对你真心纯属浪费
5楼-- · 2020-01-24 20:30

In my case it was the forward slash in my path causing the problem...

Not Work

/srv/bootstrap/

Work

srv/bootstrap/
查看更多
不美不萌又怎样
6楼-- · 2020-01-24 20:32

Check you have permission to the folder. I have just run into this and it was because the folder was owned by the www-data user not the user I was logged in to the terminal as.

查看更多
甜甜的少女心
7楼-- · 2020-01-24 20:33

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

查看更多
登录 后发表回答