I have a git repository hosting a python project. It is code for long running simulations, that takes hours-days to complete. I manage the history with git, and run the simulations on a remote server, by pulling code.
I have multiple copies of the repository on the server, which maybe at different commits. When I execute a simulation from one such folder, I want to log the git commit at which I am running the simulations. I write the input parameters of my simulations when the code starts running to a json file. I want to include the git commit hash with this file, so that I can recreate simulations results exactly by matching the commit and input parameters.
Essentially, I want to access the git commit hash of HEAD from within python code so that I can write it to a file, and am looking for simple method with no overhead.
I have come across gitpython
but they warn that: Leakage of System Resources: GitPython is not suited for long-running processes (like daemons) as it tends to leak system resources. I would prefer a method that using native python libraries.