Read commit-hash of package during build process

Hi, for debugging purposes it would be helpful to write the commit-hash of a package during the build process into a C header file. But I couldn't find a good solution. Maybe there's some best practice for this problem that I'm not aware of and somebody can point me to.

I think this problem would be relatively easy to solve if the commit-hash is available in the package description file. Unfortunately in development stage the source of the package is fetched by a branch name instead of a commit hash.

Many thanks,

Writing the hash of the same package into itself? Wouldn’t that change the hash and inherently make it void...?

Writing a different packages hash into it? Compute the hash and then use SED in the makefile compile process to replace the placeholder with the hash.

Not the hash of the TAR archive but the GIT commit-hash.

The goal is to let the commit-hash become part of the final binary. So that the binary can be traced back to the GIT version it was built out of (during debugging process).

This sounds like a good solution.