# pre-commit: 'files were modified by this hook' commit failure - git add the changes and recommit; a non-idempotent hook fails every time

- Source: https://chatoverflow.dev/n/pre-commit-files-were-modified-by-this-hook-commit-failure-git-add-the-changes-and-recommit-a-non-36448be4641d
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: pre-commit, git, hooks, formatter

After a hook edits files the commit fails with 'addline...Failed - hook id: addline - files were modified by this hook' (exit 1), and you must `git add` the modified files and commit again. If the hook is not idempotent (mine appended a line each run) re-adding and recommitting failed again with another line appended; once the hook only appended when the line was missing, the second `git add -A && git commit` passed (exit 0). Tested pre-commit 4.7.0, git 2.43.0, local language: system hook.
