KOLLITSCH.dev*
Photo by [Roman Synkevych](https://unsplash.com/@synkevych) on [Unsplash](https://unsplash.com/photos/black-and-white-penguin-toy-wX2L8L-fGeA)
Photo by Roman Synkevych on Unsplash

Stop tracking files ignored by .gitignore

Changing .gitignore does not affect files Git already tracks.

Ignore rules prevent matching untracked files from being added. Files already present in Git’s index remain tracked until they are removed from it explicitly.

The relevant command is:

Terminal window
git rm --cached

The --cached flag removes files from the index while keeping the local copies on disk.

Example

Assume .gitignore contains:

generated/

Git will ignore new files inside generated/. However, files that were added before this rule was introduced remain tracked, for example:

generated/example-file.ext
generated/cache.json
generated/debug.log
generated/output/data.json

Their changes can therefore continue to appear in git status.

List tracked files that are now ignored

Use the following command to list files that are present in the index but match the current ignore rules:

Terminal window
git ls-files --cached --ignored --exclude-standard

Limit the result to generated/:

Terminal window
git ls-files --cached --ignored --exclude-standard -- generated/

Dry-run the cleanup

Before changing the index, inspect what Git would remove:

Terminal window
git ls-files --cached --ignored --exclude-standard -z -- generated/ \
| xargs -0 -r git rm --cached --dry-run --ignore-unmatch

The null-delimited output safely handles filenames containing spaces or other unusual characters.

Stop tracking the files

When the dry-run output is correct:

Terminal window
git ls-files --cached --ignored --exclude-standard -z -- generated/ \
| xargs -0 -r git rm --cached --ignore-unmatch

This stages the files for removal from the repository without deleting them from the working tree.

For a single file:

Terminal window
git rm --cached -- generated/example-file.ext

Do not omit --cached unless the file should also be deleted locally:

Terminal window
git rm -- generated/example-file.ext

Review the staged changes with git status --short, then commit the updated .gitignore and the removals from the index:

Terminal window
git add -- .gitignore
git commit --message "chore: stop tracking ignored generated files"

List ignored untracked files

After the cleanup, the files are ordinary ignored files in the working tree.

Show ignored files alongside the normal status output:

Terminal window
git status --ignored --short

List only ignored untracked files:

Terminal window
git ls-files --others --ignored --exclude-standard

Limit the result to generated/:

Terminal window
git ls-files --others --ignored --exclude-standard -- generated/

Optionally delete ignored files locally

Use git clean only when the ignored files should also be removed from disk.

Always start with a dry-run:

Terminal window
git clean --dry-run -d -X -- generated/
FlagMeaning
--dry-runShow what would be deleted
-dInclude directories
-XDelete only ignored files

Run the deletion only after reviewing the output:

Terminal window
git clean --force -d -X -- generated/

Uppercase -X removes only ignored files. Lowercase -x also removes non-ignored untracked files and is considerably more destructive.

For generated files, caches, logs, and other local files that should remain available, git rm --cached is the appropriate operation.

Meta Information

Recent Posts

Photo by [Tigran Kharatyan](https://unsplash.com/@t1ko) on [Unsplash](https://unsplash.com/photos/a-close-up-of-an-apple-logo-on-a-silver-surface-lL1NCmptNYw)
Photo by Tigran Kharatyan on Unsplash

Keeping an old iMac useful

My old iMac's fan is dead, so heat management drives every decision here: Xubuntu 22.04 with XFCE, the 5.15 GA kernel instead of the 6.8 HWE stack, the NVIDIA 390 legacy driver, and forcing H.264 everywhere (VLC, browser, yt-dlp) since VP9/AV1 push decoding onto the CPU and cook the machine. I also block release upgrades, disable jammy-proposed, pin the kernel line, and tune thermald and the CPU governor to keep temperatures down.

Photo by [Samuel Regan-Asante](https://unsplash.com/@reganography) on [Unsplash](https://unsplash.com/photos/a-store-front-at-day-ctE7nhF4qrQ)
Photo by Samuel Regan-Asante on Unsplash

RFC 2119 for humans

RFC 2119 defines how words like MUST, SHOULD, and MAY are used in technical documentation. This short guide explains what they really mean, how to read them correctly, and how to use them to remove ambiguity and make rules explicit.

Allow me to interrupt!

Image
Image

Follower Feeds

Read an eclectic selection of Patrick's reading

Web, Tech and Development feed
Web, Tech & Development
This & That feed
This & That