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:33

Check these out:

  1. Have you looked for other .gitignore files, as there can be many of them.

  2. Also, look at REPO/.git/config to see if there is anything there.

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

查看更多
beautiful°
3楼-- · 2020-01-24 20:33

Another thing to try: I had a directory B with its own .git repository nested under my project directory A (but not as a submodule). I made some changes to B, and wanted to make it into a bonafide submodule. I believe git A was automatically ignoring B because it contained its own repository (see Nested git repositories without submodules?). I renamed the B folder, and tried to clone it again as a submodule, and that was bringing me the misleading "ignored by .gitignore" error message. The solution was to delete .git out of B.

查看更多
欢心
4楼-- · 2020-01-24 20:33

I was having the exact same problem as you. The only reply you got listed a few places to check, but none of them solved the problem for me, and from your comment I don't think for you either. I had no OTHER .gitignore files hiding lower in the directory tree; nothing in .git/config; nothing in .git/ingore/exclude

If you still have the problem, check this answer. It solved the issue for me

Basically, check for a ~/.gitignore file. Mine was called ~/.gitignore_global. I don't know when it was created (I certainly didn't make it), but I tried a ton of different git setup's when I first installed, so one of them must have put it there.

Hope his answer helps you as well!

查看更多
Rolldiameter
5楼-- · 2020-01-24 20:34

Another reason for receiving this error message from git is when executing the git submodule add command while a previous git command has crashed and left the lock file (this can happen, for instance, when you use custom scripts which include git commands and you haven't noted the crash).

If you execute the command git commit instead, while none of the conditions have changed (git submodule add will keep yelling that your .gitignore files are to blame), you'll see another error report instead:

$ git commit -a
fatal: Unable to create '..../.git/index.lock': File exists.

If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.

and indeed deleting the lockfile:

rm .git/index.lock

resolves the issue. (This happens to git version 2.1.0.9736. It may be fixed in future git releases.)

查看更多
别忘想泡老子
6楼-- · 2020-01-24 20:43

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.

查看更多
Evening l夕情丶
7楼-- · 2020-01-24 20:43

For me I accidentally had a wildcard in my ~/.gitignore_global file. Maybe check there?

查看更多
登录 后发表回答