Why Git Still Tracks a File After You Add It to .gitignore
Check the index first. Ignore rules govern untracked files. A file already in the index can continue to show changes even when its path matches the new rule.
Inspect the tracked and ignored states
In this synthetic repository, the generated artifact is dist/report.json. Run git ls-files -- dist/report.json. If it prints the path, the file is tracked. To inspect whether the ignore pattern would otherwise match, use git check-ignore -v --no-index -- dist/report.json. The second command reports the pattern and source file when a rule matches.
Stage the change only for the intended artifact
After confirming that the team intends to remove the generated file from future revisions, run git rm --cached -- dist/report.json and stage the ignore rule. This keeps the file in your current working tree and stages its removal from version control. The committed change can remove the tracked copy from other checkouts. If Git says the index has distinct staged content, inspect it before proceeding.
Review the staged diff and test regeneration
Check git diff --cached --name-status for the expected removal and rule change. The file should remain on disk. A fresh checkout will need to regenerate it, so verify that build workflow in a disposable checkout when required. Ignore rules only affect future tracking. Prior commits can still contain the file.
댓글
댓글 쓰기
안녕하세요 :)