lint-staged Pre-Commit Failure Drops Previously Staged Files
Historical: lint-staged was removed on 2026-03-01. Kept for reference.
title: lint-staged Pre-Commit Failure Drops Previously Staged Files category: workflow-issues created: 2026-02-20 symptoms:
- Commit succeeds but contains fewer files than expected
- ‘“git add” files disappear from staging after a pre-commit hook failure and retry’
- Partial commits despite staging all files before committing tags:
- lint-staged
- pre-commit
- git
- partial-commit
- agent-team related:
- docs/solutions/workflow-issues/agent-team-orchestration-at-scale.md
- docs/solutions/workflow-issues/batched-commits-anti-pattern.md
Historical (2026-03-01): lint-staged was removed from the pre-commit hook. The pre-commit hook now runs gitleaks only. This document is kept for reference — the described problem no longer applies. See
.husky/pre-commitandtools/precheck.sh --fix.
lint-staged Pre-Commit Failure Drops Previously Staged Files
Problem
When git commit triggers lint-staged and a linter fails (e.g., clippy error), the commit is aborted — but
previously staged files are silently unstaged. A subsequent fix-and-retry commits only the files that were re-staged,
not the full original set.
Symptoms:
git add16 files →git commit→ clippy fails → fix clippy error →git addthe fixed file →git commit→ only 3 files in the commit (the rest vanished from staging)- No error message indicates files were dropped
git statusafter the failed commit shows previously staged files as “modified” (unstaged)
Investigation
Steps Tried
- Staged all ~16 files with
git add→ verified withgit statusshowing all staged - Ran
git commit→ lint-staged triggered → clippy foundunnecessary_map_or→ commit aborted - Fixed the clippy error in-place
- Staged only the fixed file → ran
git commitagain → commit succeeded - Discovered: commit only contained 3 files, not the original 16
Root Cause
lint-staged uses a stash-based isolation strategy:
- Before running linters:
git stashsaves unstaged changes (including the working tree state) - Runs linters against only the staged files
- If linters fail: restores the stash to “revert to original state”
The restore operation (git stash pop) replaces the entire index, effectively unstaging all previously staged
files. The working directory retains the modifications, but the staging area is reset.
This is by design — lint-staged wants to guarantee that a failed commit leaves the repository in the exact state it was in before the commit attempt. But the side effect is that your carefully staged files are all unstaged.
Timeline: git add file1..file16 # 16 files staged git commit # triggers lint-staged ├─ lint-staged: git stash # saves unstaged state ├─ lint-staged: run clippy # FAILS └─ lint-staged: git stash pop # restores pre-commit state # → ALL 16 files now UNSTAGED git add fixedFile # only 1 file staged git commit # succeeds with 1-3 filesSolution
After any lint-staged failure, re-stage ALL intended files before retrying the commit.
Workflow
# After a pre-commit hook failure:git status # Check — files are now unstagedgit add file1 file2 ... fileN # Re-stage everything (not just the fix)git commit -m "..." # Retry with full stagingFor Agent Teams (Leader-Commits Pattern)
When the leader is committing on behalf of multiple agents:
# Collect all agent files into a list BEFORE the first commit attemptFILES="path/to/file1 path/to/file2 ..."
# After any failure, always re-add the full listgit add $FILESgit commit -m "..."Implementation Notes
- Always check
git statusafter a failed commit — verify your staging area matches expectations - The fix itself may need staging too — if you edited a file to fix a linter error, that file needs to be staged alongside the re-staged originals
- This compounds with multiple failures — each failure cycle drops staging again
Prevention
Best Practices
- After any pre-commit failure, run
git statusbefore retrying - Keep a list of intended files when committing large changesets
- Consider running linters manually before commit (
cargo clippy,pnpm lint) to catch errors before lint-staged gets involved - In agent team workflows, the leader should maintain the full file list and re-stage everything on retry
Warning Signs
- Commit message says “wave 1 + wave 2” but
git show --statonly shows 3 files - Post-commit
git statusshows unexpected modified files - A second commit is needed to “catch” the remaining files
Related Patterns
This interacts with two other documented lint-staged behaviors:
- lint-staged gotcha (directory renames): Renaming directories exposes pre-existing lint errors in newly-matched files → fix as part of the rename commit
- lint-staged partial staging: When files are both renamed (staged) AND modified (unstaged), lint-staged stashes unstaged changes → stage both rename and modifications together
All three patterns stem from lint-staged’s stash-based isolation strategy.
References
- Discovered during INK-333 review remediation (commit
4ccfc7bwas partial;6a55068caught the remaining files) - lint-staged documentation: https://github.com/lint-staged/lint-staged#how-can-i-ignore-unstaged-changes-and-only-lint-the-staged-changes
Derive Copy Cross-Agent Ripple: Adding Copy to a Shared Type Breaks Downstream Clippy Next
Parallel Agent Orphaned Module Wiring
Was this page helpful?
Thanks for your feedback!