Problem
When committing changes in a JetBrains IDE, the entire file is committed even though only specific lines or hunks were selected for inclusion in the Commit tool window. The partial selection appears to have no effect — all modifications in the file end up in the commit.
Cause
An active Git hook (typically pre-commit) configured in the project's .git/hooks/ directory re-stages or modifies the file during the commit operation, overriding the partial selection made in the IDE.
The IDE performs a partial commit by adjusting the index to contain only the selected hunks, running the commit, and then restoring the working tree. If a hook runs commands such as git add, auto-formatters, or linters that re-stage files, the unselected changes are added back to the index and included in the commit.
By default, the IDE runs configured Git hooks during a commit (the Run Git Hooks option in Commit Options is enabled).
Resolution
Verify that a Git hook is the cause
- In the Commit tool window, open the Commit Options dropdown (gear icon).
- Disable the Run Git Hooks option.
- Repeat the commit with only the selected hunks.
If the partial commit now contains only the selected changes, a Git hook is responsible.
Permanent fix
- Inspect the scripts in the project's
.git/hooks/directory (commonlypre-commit). - Identify the hook that modifies or re-stages files. Hooks that run
git add, formatters, or linters across the working tree are typical causes. - Adjust the hook so it operates only on already-staged changes — for example, by using
git diff --cachedinstead of operating on the working tree — or remove the hook if it is no longer needed.
For details on hook behavior, refer to the Git hooks documentation.
Workaround
Keep the Run Git Hooks option disabled in Commit Options when performing partial commits. The hooks can be re-enabled for full-file commits.
Comments
0 comments
Please sign in to leave a comment.