Skip to content
Latchkey

protoc generated code out of date (git diff) in CI

A common CI gate regenerates code and runs git diff --exit-code; a non-empty diff means the committed generated files are stale. The fix is to regenerate and commit, or to align the tool versions that produced the diff.

What this error means

A "check generated code" step fails after git diff --exit-code, listing changed *.pb.go / *_pb2.py files, even though no proto was intentionally edited.

Terminal
Regenerating protobuf code...
diff --git a/gen/api/v1/user.pb.go b/gen/api/v1/user.pb.go
Error: generated code is out of date; run 'buf generate' and commit the result
Error: Process completed with exit code 1.

Common causes

The generated files were not regenerated and committed

A proto changed but the developer did not re-run codegen, so the committed artifacts lag the schema.

CI uses different tool versions than local

A newer protoc or plugin in CI emits slightly different output, producing a diff even when the schema is unchanged.

How to fix it

Regenerate and commit

  1. Run the exact generate command CI runs locally.
  2. Commit the updated generated files.
  3. Push so the diff check passes.
Terminal
buf generate
git add gen && git commit -m "regenerate protobuf code"

Pin identical tool versions

Match protoc and plugin versions between local and CI so codegen output is byte-for-byte reproducible.

buf.gen.yaml
version: v2
plugins:
  - remote: buf.build/protocolbuffers/go:v1.34.2
    out: gen

How to prevent it

  • Pin every codegen tool version so output is deterministic.
  • Run the same generate command in a pre-commit hook.
  • Keep the diff check as a required status so stale code never merges.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →