Search code examples
git

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


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.


Solution

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