74

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.

jonfer
  • 1,524
  • 2
  • 14
  • 23
  • Git is not detected changes to the file in that you have already added and committed it? Or Git is not detected the file exists unless the name is changed? – fearmint Mar 14 '12 at 18:08
  • first try "git add ." and then check git status. if that doesn't work, navigate to that file directory and try "git add style.css" and do another git status... i think that will work – Kristian Mar 14 '12 at 18:11
  • 1
    The file is already added and commited in the past. But right now doesn't detect the changes, even when I delete de file – jonfer Mar 14 '12 at 18:12
  • Have you checked some of the other gitignore places? http://stackoverflow.com/questions/9436405/git-is-ignoring-files-that-arent-in-gitignore – dule Mar 14 '12 at 18:12
  • "git add ." and "git add style.css" didn't work, thats the first thing I tried – jonfer Mar 14 '12 at 18:14
  • Are you by any chance using a case-insensitive file system? Perhaps OSX? – Paul Beckingham Mar 14 '12 at 18:15
  • Are there any entries in .gitignore in any of the parent folders which might match this file? – bluesman Mar 14 '12 at 18:24
  • @PaulBeckingham could something like this be a case-sensitivity problem? how? – inger Mar 14 '12 at 18:48
  • I'm in Mac OS X. I have check all the .gitgnore files and I dont find it in any of them... :/ – jonfer Mar 14 '12 at 19:09
  • Is it possible that you checked in the 'style.css' file using different casing? Such as 'Style.css'? The file system is case-insensitive, but git is not. I have seen this many times. – Paul Beckingham Mar 14 '12 at 23:59
  • FWIW I had this problem and solved it by deleting the offending file with "git rm". After committing the delete I was able to add back the modified file. – Mauricio Scheffer Jul 15 '13 at 21:03
  • For reference, this file was also used on my system: ~/.gitignore_global (MacOSX, git 2.11.0) – William Fink Apr 25 '17 at 13:20

17 Answers17

113

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.

kenorb
  • 155,785
  • 88
  • 678
  • 743
  • 12
    git add -f . fixed it for me without cloning the repository. – Joe Nov 13 '16 at 11:16
  • 3
    This should be the accepted answer since it shows where the problem actually lies. – Michael Thiel Jan 11 '17 at 15:05
  • 1
    This fixed things for me. I had a whole folder not showing nothing wrong or out of place anywhere. Running git add -f on one of the files brought everything back to life. Really gets frustrating GIT with its randoms at times. Thanks! – Jimbo Nov 10 '17 at 01:23
  • Thanks. Just as I suspected, the path was set as a submodule. But it wasn't anywhere in configuration or can be removed with `submodule deinit`. Luckily I just created the repo, so I just removed the the `.git` folder and re-inited git. – andho Nov 14 '18 at 13:54
  • `git add -f %relativepath%` . eg: `git add -f folder\file.xml` to be more explicit – Graviton May 27 '19 at 10:12
19

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.

Icestorm0141
  • 662
  • 2
  • 9
  • 21
  • This worked for me too, but it was worse in that my .git folder was hidden, which it typically isn't in Windows. I had to use a terminal to see and delete it. – André C. Andersen Mar 24 '22 at 23:48
12

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

Bombe
  • 81,643
  • 20
  • 123
  • 127
  • 2
    this answer didn't really solve the question. the comment did. – Gerald Apr 09 '16 at 16:55
  • 1
    Facepalm moment: make sure your files are in the correct directory. Was working off a flash drive on a different machine and dropped the folder in the wrong spot when I got back to my main machine. Digging for the .git folder manually clued me in. :/ – brichins Jan 10 '17 at 00:54
8

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.

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • 4
    How would one check whether one had run either of those commands? – Dave Schweisguth May 22 '14 at 18:11
  • 1
    Run [`git ls-files -v `](https://git-scm.com/docs/git-ls-files#git-ls-files--v). Any lowercase letter means `--assume-unchanged` was applied; `S` means `--skip-worktree` applied, and `s` means both applied. Try grepping the codebase for those options; I've worked on repos with scripts that run `--assume-unchanged` to prevent people from checking in updates to config files -- very annoying. – jjlin Apr 26 '17 at 18:59
4

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.

Lucas
  • 16,930
  • 31
  • 110
  • 182
2

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
MzC_
  • 29
  • 1
  • I tried this and it essentially resolved my problem however the .gitignore file was left unchanged. There is a blank line at the end of .gitignore; I wonder if that is the issue? – Highly Irregular Mar 24 '15 at 22:49
1

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

dessalines
  • 6,352
  • 5
  • 42
  • 59
1

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.

1

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

meth
  • 1,887
  • 2
  • 18
  • 33
0

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.

Vijay Kalidindi
  • 165
  • 3
  • 12
0

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.

user19292
  • 391
  • 2
  • 3
0

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

Cutton Eye
  • 3,207
  • 3
  • 20
  • 39
0

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

Tom McDonald
  • 1,532
  • 2
  • 18
  • 37
0

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

MintWelsh
  • 1,199
  • 13
  • 22
0

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.

DariusV
  • 2,645
  • 16
  • 21
0

This can happen as well when you change a file's casing (e.g. HelloWorld.txt > helloworld.txt). If this is the case for you, see How do I commit case-sensitive only filename changes in Git?

Ned
  • 490
  • 4
  • 15
-2

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.

lcharbon
  • 3,030
  • 2
  • 16
  • 18