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

Git

Git Problem Overview


I have a file called "style.css" and git is not detecting it. It doesn't detect it if I delete it either, but it does detect if I change the name of the file. But I need it with that name. The file is not in the .gitignore file. This is driving me crazy!

I would appreciate some help.

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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.

Solution 3 - Git

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

Solution 4 - Git

Apart from the the gitignore and other places to check for ignore patterns, check if you had run git update-index --assume-unchanged or git update-index --skip-worktree. If so, unset them.

Make sure that there is not some weirdness in the repo or parent of the file under concern whereby it has a .git of its own.

Try doing a clone of your repo and see if you see the same in the cloned one. If so, try cloning onto a different machine / VM and check. That will give you some idea of what's going wrong where.

Solution 5 - Git

I had the same problem (components/dashboard/js-dev/training/index.js wasn't being tracked for some reason), so I did the following:

$ git check-ignore -v components/dashboard/js-dev/training/index.js
$ (gave me nothing)

$ git check-ignore -v components/dashboard/js-dev/training/
$ /Users/User/.config/git/ignore:23:    components/dashboard/js-dev/training/

Anyways, I found this to be quite weird, so then I took a look at this file, /Users/User/.config/git/ignore, and this is what it looked like:

(this is line 1)
# Automatically created by GitHub for Mac
# To make edits, delete these initial comments, or else your changes may be lost!

*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

And it turns out that line 23 is in fact the one between .com.apple.timemachine.donotpresent and # Directories potentially created on remote AFP share, in other words, it was a completely empty line!

I tried removing all the extra newlines so my file looked like this:

# Automatically created by GitHub for Mac
# To make edits, delete these initial comments, or else your changes may be lost!
*.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

I run git status, and I notice that it's now picking up components/dashboard/js-dev/training/. I run git add components/dashboard/js-dev/training/, and all works fine again.

Hope this helps someone - this issue got me stuck for an unnecessarily long amount of time.

Solution 6 - Git

I had a similar issue and solved it.

I was getting this error message when running the git add command:

The following paths are ignored by one of your .gitignore files:
<file>
Use -f if you really want to add them. 
fatal: no files added

So I tried to force Git to solve the issue for me by adding a -f to the git add command. This would normally force Git to adjust the .gitignore file and you will then be able to see the required change or problematic setting.

In my particular case there seemed to be some weird issue with the newline at the end of the .gitignore file. Here how Git fixed the problem:

-RemoteSystemsTempFiles
+RemoteSystemsTempFiles
\ No newline at end of file

Solution 7 - Git

Extra note, I ran into this problem and found that changes to files weren't being added to commits. Nothing seemed to work, except Right clicking the project, and doing:

Team > Advanced > No assume unchanged

Solution 8 - Git

I also ran into this issue and it seems to be a problem with EGit plugin for Eclipse. Like @user1655478 said in previous comment, selecting the project in the projects view, performing a right click and selecting "Team > Advanced > No assume unchanged" fixed the problem for me.

Solution 9 - Git

Another reason to this problem may be the .gitignore_global file. In my case, it was automatically produced by Sourcetree app while i was ignoring file. It was in my user path(/Users/user_name/.gitignore_global).

Solution 10 - Git

If your project is a maven project, check if you changed the src file or the target file. That's what I did recently. With the file path reference being too long, I failed to notice the 'target' in the path. All good after 1 hr of agony.

Solution 11 - Git

I encountered another cause for this. Probably very rare circumstances.

I copied my entire repository to another folder to work on it. Changes I made to a submodule just weren't being detected by git. Turned out that the .git file in the submodule folder contained an absolute file reference to the original copy. As soon as I corrected the file reference to point to my working copy all was well.

Solution 12 - Git

some want to add an empty folder for some reasons If the content of the folder is empty, then there is no reason for git to mention it.

A convention says that you might want to add a file .keep to it. which could also any other file.

see here or here

Solution 13 - Git

this happened to me when I was working on a branch I had just created called 'am'. I got on another dev station and couldn't see the file I added to the branch. In order to see the file I ran the following command

git checkout am
git branch --set-upstream-to=origin/am
git pull

after the pull all the changes came down

Solution 14 - Git

first check in your git repository to make sure that the file isn't there, sometimes capitalized letters can mess up a file being recognized but won't be recognized as a change, especially in a file extension like .JPG

(for some reason this happened to me although the file was saved the same as the others the extension was capitalized only on one and wouldn't appear on the site)

'if' this is the problem check 'show file name extensions' in relevant folder, rename file as something else with lower case extension, git add and commit and then rename it as originally wanted but keeping the lower case extension, because of the more obvious change it will be rewritten and not ignored

Solution 15 - Git

In my case I check my .gitignore_global, I found all my swift files ignored, I just removed the line *.swift and git recognized my ones.

Solution 16 - Git

Quitting the GitHub app worked for me.

Symptoms: My repo is on google file stream. I could only see modified files when running git status but the GitHub app showed all changes.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjonferView Question on Stackoverflow
Solution 1 - GitkenorbView Answer on Stackoverflow
Solution 2 - GitIcestorm0141View Answer on Stackoverflow
Solution 3 - GitBombeView Answer on Stackoverflow
Solution 4 - GitmanojldsView Answer on Stackoverflow
Solution 5 - GitLucasView Answer on Stackoverflow
Solution 6 - GitMzC_View Answer on Stackoverflow
Solution 7 - GitthoulihaView Answer on Stackoverflow
Solution 8 - GitDavid Escalona OzaetaView Answer on Stackoverflow
Solution 9 - GitmethView Answer on Stackoverflow
Solution 10 - GitVijay KalidindiView Answer on Stackoverflow
Solution 11 - Gituser19292View Answer on Stackoverflow
Solution 12 - GitCutton EyeView Answer on Stackoverflow
Solution 13 - GitTom McDonaldView Answer on Stackoverflow
Solution 14 - GitMintWelshView Answer on Stackoverflow
Solution 15 - GitDariusVView Answer on Stackoverflow
Solution 16 - GitlcharbonView Answer on Stackoverflow