0

Git doesn't stop tracking specific autogenerated file in the project. I have a specific file that autogenerated when the project run: platform/views/index.html. I have added it to .gitignore, to .git/info/exclude, run on it git rm --cached platform/views/index.html but every time it's recreated git keep asking me what do I want to do with it.

How can I cause git to stop tracking this file once and forever? Thank you.

My .gitignore file:

dump.rdb
*.DS_Store
.vscode
.sfdx
npm-debug.log
**/.idea
**/node_modules
.vs
**/.history
newrelic_agent.log
platform/api/modules/interactions/entity-mock.js
platform/views/
Anatoly
  • 5,056
  • 9
  • 62
  • 136

3 Answers3

2

Files already committed will not be ignored.

  1. Commit your .gitignore
  2. Delete the file in question
  3. Do another commit
  4. Let the file be autogenerated again

And then verify that it isn't part of new commits after the steps above.

jgauffin
  • 99,844
  • 45
  • 235
  • 372
1

If you want to ignore all files in the directory, use:

platform/views/**

in the gitignore. If you just want to ignore the one file, use:

platform/views/index.html

The pattern platform/views does not match the file, so your current .gitignore is not ignoring the file.

William Pursell
  • 204,365
  • 48
  • 270
  • 300
  • "your current .gitignore is not ignoring the file" are you sure ? from what I see the OP's pattern `platform/views/` should make git ignore all files within that directory (tested on my machine, git v2.31/linux) – LeGEC Jun 07 '21 at 13:56
  • @LeGEC, actually I would like to get some clarification regarding this pattern too, why it works for `node_modules` but doesn't work for other folder? I marked this answer as correct because it looks that after I've added `**` it started to ignore it finally. – Anatoly Jun 09 '21 at 14:04
  • AFAICT, `platform/views` should match, and as @LeGEC points out, my initial comment seems incorrect. It's not clear to me why you're seeing this behavior. – William Pursell Jun 09 '21 at 14:34
1

I would suggest inspecting several things :

a. run git check-ignore -v platform/views/index.html

If the file is ignored : you will see a message, mentioning the gitignore file and the pattern within that gitignore file that ignores this specific path ;
if the file is not ignored : you will see an empty output.

b. if file is not ignored, run git rm --cached platform/views/index.html again, and confirm that after that, the file is ignored.

You may commit the result if relevant.

c. trigger your generation job manually, and see if that file is tracked again.

This would mean that your job runs the equivalent of git add -f platform/views/index.html somewhere.

LeGEC
  • 46,477
  • 5
  • 57
  • 104