0

I know there are similar questions, but none of those solutions worked for me, hence creating a new question.

I have the following .gitignore section:

#generated sources in tfliteparser/tflite
tfliteparser/tflite/
kernels/native_funcs.cpp

However, when I run git status, both the file and the folder appear in the untracked files section:

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        ../.DS_Store
        kernels/native_funcs.cpp
        network_summary.dat
        tfliteparser/tflite/

I am assuming, that since these objects are in the untracked section, they were never added to the index, right? Why do they appear then?

What I have tried:

git rm --cached kernels/native_funcs.cpp

This gives:

fatal: pathspec 'kernels/native_funcs.cpp' did not match any files

However, this file is there. If I ls it, OS sees it. I also tried this. Same result.

I know for a fact, that .gitignore file gets loaded since if I add network_summary.dat file to it, it gets ignored.

Any ideas, please?

drsealks
  • 2,282
  • 1
  • 17
  • 34

1 Answers1

2

With ../.DS_Store I see that the current directory is not the root of the repository. Your ignore patterns contain slashes so they match only at the directory level where your .gitignore resides. If the .gitignore is at the root of the repo your patterns don't match.

To make them match either prefix them with the subdirectory name or with an asterisk:

# .gitignore
<subdir>/tfliteparser/tflite/
*/kernels/native_funcs.cpp

$ git rm --cached kernels/native_funcs.cpp
fatal: pathspec 'kernels/native_funcs.cpp' did not match any files

This means kernels/native_funcs.cpp is not in the index (the file was not git added). git rm --cached only removes from index, not files.

phd
  • 82,685
  • 13
  • 120
  • 165