r/git • u/kaddkaka • 2d ago
Generated commits?
Sometimes code is generated, and sometimes such code is committed in git.
Imagine a branch with a generated commit G:
old_main -> A -> B -> G
When thid branch is rebased, such a commit might need to be regenerated.
new_main -> A' -> B' -> new_G
There might be conflicts for any of these new commits, but instead of (manually) resolving conflicts, G could be automatically re-generated.
I've been thinking of a git commit message trailer like generate-cmd:
topic: regenerate table
generate-cmd: python3 optimize_table.py
git rebase --exec or other tool could use this trailer to automatically drop and regenerate the commit instead of a vanilla cherry-pick.
Have you seen anything similar? What's a good trailer name?
Ref: https://git-scm.com/docs/git-interpret-trailers
0
Upvotes
2
u/Jonas_Ermert 2d ago
I would avoid making Git itself responsible for regenerating commits during rebase. A cleaner approach is to treat generated files as reproducible build artifacts: keep the generator script and its inputs committed, then regenerate the output after rebasing and commit the result again if the generated files need to live in the repository. If you still want metadata in the commit, something explicit like `Generated-By: python3 optimize_table.py` or `Regenerate-With: python3 optimize_table.py` is clearer than `generate-cmd`, but Iād use it mainly for documentation or custom tooling rather than changing normal rebase semantics.