I committed `dist/` and other generated files into three tiny Git projects before I understood `.gitignore`. Adding those paths to `.gitignore` stops new untracked files, but Git still tracks the ones already committed. I think I need `git rm --cached` so they disappear from the index without deleting my local build output. Is that right? I don't need to rewrite shared history; I just want future commits to contain source files and configuration, not the generated artifacts.
Learning Git after accidentally committing generated files to several small projects
- programming-help
- accidentally
- committing
- generated
78
5 replies
Yes, `git rm --cached` is the right idea for files you already committed. Add them to `.gitignore` first, then remove them from the index so...
Yes, `git rm --cached` is the right idea for files you already committed. Add them to `.gitignore` first, then remove them from the index so Git stops tracking them.
That’s how I’d do it too. It leaves the local files on disk, which is the part people usually care about.
One thing I’m still fuzzy on: if there are already generated files in the repo, do I need to do `git rm --cached` on each path separately or can I give it a folder?
You can do the folder. For example, removing `dist/` from tracking will drop the tracked contents from the index without deleting your local...
If the project is tiny, I’d also check that nothing else generated is still being committed by accident, like logs or caches. That’s usually...