Problem
Selecting specific chunks in the Commit tool window via checkboxes commits the entire file instead of only the selected chunks. The label next to the file name in the Commit tool window (for example, 1 of 6 changes) correctly reflects the selection, but after committing, all changes from the file appear in the commit. The diff view may also display an Unable to calculate diff message.
The behavior reproduces across multiple projects.
For reference on the expected behavior, see Select chunks in the Commit dialog.
Cause
A custom Git hook in the project's .git/hooks directory (typically pre-commit) modifies or re-stages files during the commit operation. Common examples include formatters, linters, or auto-fix scripts. When the hook re-stages files, the partial chunk selection performed by the IDE is overwritten, and the full file content ends up in the commit.
Resolution
- Open the project root in a file explorer or terminal and inspect the
.git/hooksdirectory for active hooks (files without the.sampleextension). - Temporarily disable the suspected hook by renaming it (for example, rename
pre-committopre-commit.disabled). - Retry the partial commit in the Commit tool window.
- If the partial commit succeeds with the hook disabled, the hook is the cause. Update the hook script so it does not modify or re-stage files during the commit — run formatters or linters in check-only mode, or move them to a
pre-pushhook or CI step.
Workaround
If the hook cannot be modified immediately, move unwanted chunks to a separate changelist before committing:
- In the Commit tool window, open the diff view for the file.
- Right-click the unwanted chunks and select Move to Another Changelist.
- Commit the active changelist, which now contains only the desired chunks.
See Manage changelists for details on changelist operations.
Comments
0 comments
Please sign in to leave a comment.