CI "generated files differ, run make generate" git diff gate in CI
A common CI gate runs the codegen command, then git diff --exit-code over the generated files. A non-empty diff means the committed generated code does not match what the current source produces, so the job fails and tells you to regenerate.
What this error means
The job prints a diff of generated files and fails with a message like "generated files are out of date, run make generate and commit", exiting non-zero on git diff --exit-code.
+ git diff --exit-code gen/
diff --git a/gen/api.pb.go b/gen/api.pb.go
@@
- // outdated generated content
+ // regenerated content
Error: generated files differ. Run 'make generate' and commit the result.Common causes
Source changed but generated code was not regenerated
A .proto, schema, or spec changed and the author did not re-run codegen, so the committed output is stale.
A different generator or plugin version in CI
CI uses a different version of the generator than the author, so the regenerated output differs even without a source change.
How to fix it
Regenerate and commit the output
- Run the project codegen command locally.
- Commit the regenerated files so they match the source.
- Push, and the diff gate passes.
make generate
git add -A
git commit -m "Regenerate generated code"Pin generator and plugin versions everywhere
Make CI and local use the exact same tool versions so identical source always produces identical output.
- name: Check generated code is up to date
run: |
make generate
git diff --exit-codeHow to prevent it
- Pin codegen tool and plugin versions across local and CI.
- Run codegen in a pre-commit hook so output never drifts.
- Keep one documented
make generatetarget as the source of truth.