pre-commit "end-of-file-fixer...Failed" in CI
The end-of-file-fixer hook ensures each file ends in exactly one newline. When it has to change a file, it edits it and reports "Failed" with "files were modified by this hook", which fails the CI run because the working tree changed.
What this error means
pre-commit shows "end-of-file-fixer.........Failed" with "files were modified by this hook" and lists the files it fixed. Locally the fix is applied; in CI it fails because the change was not committed.
end-of-file-fixer........................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
- files were modified by this hook
Fixing config.yamlCommon causes
A file has no final newline or has extra blank lines
The hook enforces exactly one trailing newline; a missing newline or multiple blank lines at EOF triggers a fix.
The fix was not committed before CI ran
pre-commit in CI runs the same hook; because it edits files, an uncommitted fix fails the check even though it "passed" after editing.
How to fix it
Run the hook locally and commit the result
- Run
pre-commit run end-of-file-fixer --all-fileslocally. - Stage and commit the files it modified.
- Push so CI runs against already-fixed files.
pre-commit run end-of-file-fixer --all-files
git add -A && git commit -m "Normalize end-of-file newlines"Install pre-commit as a git hook so it fixes on commit
Installing the hook means the fixer runs before each commit, so files reach CI already normalized.
pre-commit installHow to prevent it
- Install pre-commit locally so fixers run before every commit.
- Enable "insert final newline" in your editor.
- Commit the fixer's changes rather than pushing unfixed files.