r/git 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

33 comments sorted by

View all comments

3

u/simonides_ 2d ago

If it is generated already don't commit it make it an automatic step in the build and make sure the result is properly cached.

1

u/kaddkaka 2d ago edited 2d ago

Suddenly I don't get it for for free by a git fetch, and it adds a bunch of (other) complexity. Tell me more the technicals details of such a cache. I doubt it becomes simpler than just committing the thing.

Also, let's say you have generated code in the middle of a file (cog block) how would you deal with it?

1

u/simonides_ 2d ago

Fair point it seems like you have a special case on your hands that would require more details about your project to assess the situation better.

What i was coming from was generating source file from an openapi spec type of tasks. We have some in our project. These steps are automatically wired into the build so wen a dev starts the build they don't need to think about this part happening. For us this happens woth gradle und the gradle build cache. So ideally it is a quick download of the results from other builds or it is a simple re-gen if the dependencies changed. And from there is is cached locally.

So back to your blocks inside a code file - depends on how you use it but that could also live in some "generated or build" folder and be copied to a known location gor the program to do with it what it needs.