agent committed node_modules by accident - the upgrade PR was 40,000 files
Shrinks an upgrade PR that accidentally committed node_modules. Use it when a dependency PR shows tens of thousands of files. Key trigger: the PR diff is dominated by node_modules paths. Not for: a legitimately large but coherent change, like a lockfile regeneration plus vendored assets.
TL;DR
node_modules got committed, turning a one-line bump into a 40,000-file PR. Remove the directory from git tracking, add it to .gitignore, and rewrite the PR so it only carries the lockfile and manifest changes.
Error
agent committed node_modules by accident - the upgrade PR was 40,000 filesSteps
Confirm the scope: check the PR file list for nodemodules paths. Expected output: The bulk of the diff is nodemodules content.
Remove it from tracking with git rm -r --cached nodemodules (keep the files on disk) and add nodemodules/ to .gitignore. Expected output: git status no longer lists the directory.
If the PR is already open, force-push the cleaned branch, or close it and open a fresh PR with only the manifest and lockfile changes. Expected output: The PR shows the bump and its lockfile diff, nothing else.
Add a pre-commit hook or CI check that fails when node_modules paths appear in a commit. Expected output: The accident cannot repeat silently.
Have the agent verify PR size before requesting review; anything over your threshold gets inspected first. Expected output: Oversized PRs are caught by the author, not the reviewer.
When to use
- A PR suddenly contains thousands of unexpected files
- The diff is dominated by node_modules
- You are setting up guardrails for agent-committed changes
When not to use
- A large diff from a lockfile regeneration; that is expected churn
- Vendored dependencies committed on purpose; that is a policy choice
- Binary asset PRs with legitimately many files
Variant phrasings
upgrade PR has 40000 files all in node_modules
node_modules committed to git by accident
remove node_modules from a pull request
Why it happens
The agent ran npm install in a repo without a .gitignore (or with a stale one), then committed everything. Install output is local build state, not source, and committing it multiplies the diff by every transitive file.
Edge cases
- If node_modules was committed on main long ago, removing it rewrites history for everyone; coordinate the cleanup.
- Some legacy deploys package node_modules; move that step to the build pipeline instead of the repo.
- git rm --cached leaves the directory on disk, so local dev keeps working.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_TsN7P4Y-PejCDZ6-kGLtUA