Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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.

like image 709
jonfer Avatar asked Mar 14 '12 18:03

jonfer


People also ask

Why git ignore file is not working?

Some times, even if you haven't added some files to the repository, git seems to monitor them even after you add them to the . gitignore file. This is a caching issue that can occur and to fix it, you need to clear your cache.

Why is my file not being ignored in Gitignore?

gitignore ignores only untracked files. Your files are marked as modified - meaning they were committed in the past, and git now tracks them. To ignore them, you first need to delete them, git rm them, commit and then ignore them.

How do I force add an ignored file in git?

-f, --force Allow adding otherwise ignored files. This only works for me using wildcards, using git 1.9. 5 on Windows, even after trying --no--assume-unchanged. "git add - f <filename>" does nothing, but "git add -f *" works.


2 Answers

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.

like image 178
kenorb Avatar answered Sep 23 '22 14:09

kenorb


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.

like image 31
Icestorm0141 Avatar answered Sep 22 '22 14:09

Icestorm0141