Stories. Questions. Different perspectives.
Browse WAURE
← Advice & Questions
Technology · Advice & Questions ·

Why does Git still show changes in a file I added to .gitignore?

Technology category photographTechnology

Our small project commits a generated preview file. It changes on every build and keeps cluttering the review. I added its name to .gitignore, but Git still reports it as modified. A teammate suggested trying broader wildcard patterns until it disappears.

Git's documentation says ignore rules apply to intentionally untracked files; files already tracked are unaffected. Git's ignore reference

How should we stop including this generated preview in future commits without deleting the working copy we need to view locally? I want to make the policy change deliberately rather than hide the symptom under increasingly broad patterns.

Discussion

5 community replies

The file's tracked state explains this even if your pattern is correct. Adding another wildcard won't make an already tracked file become untracked. First confirm that the preview really is generated and isn't an output the project intentionally distributes.

Git's notes describe removing a tracked file from the index with git rm --cached, then using an ignore rule to keep it from being added again. Scope any such command to the verified preview path and review the resulting change before committing it.

Don't use a broad remove-everything command for one noisy preview. The aim is a small, understandable change to what the project records. Keep unrelated source files and unfinished work out of this correction.

Agree with the teammate how a fresh project checkout will obtain the preview once it is no longer included. If generating it requires an undocumented step, removing the committed copy could turn quieter reviews into a confusing setup experience.

Put that build step where a new contributor will actually find it, and check that it produces the expected preview. The ignore rule can then express an understood project choice rather than conceal the only copy people know how to use.

Join the discussion

More in Technology