Reproducible C++ builds by logging git hashes November 14, 2025 Sometimes I am in the difficult situation where I have written a program which writes some kind of output to disk, and I want to remember which version of my program produced this output. This is really common for me at the moment due to my research, which always seems to involve a lot of trial and error algorithm design. I think that similar problems exist in all kinds of other areas, but particularly during rapid development, because once software has been properly deployed and versioned it鈥檚 quite trivial to just put the version number in the logs. For a slightly more, but not very, concrete example: I鈥檓 working on an algorithm implementation right now. I won鈥檛 say too much about the details yet, but it takes a number of configuration options. These, of course, I can quite easily write to the log file. The program also has lots of implementation details that can be tweaked, really dozens of things I could change, and I keep coming up with new ideas I want to try. This means that I end up with a folder full of outputs generated by code that probably doesn鈥檛 even exist anymore, and which I wouldn鈥檛 be able to reproduce purely by running the current version of the program with whatever configuration options are specified in the log file. This also isn鈥檛 the first time I鈥檝e had a very similar problem. I assume (hope) it鈥檚 not just me, so I thought I鈥檇 write up the solution I came up with. Git commit hashes As you likely know, you can identify git commits by their hash, which are long strings of hexadecimal digits, such as b5a994c260105b7cc979aead986532b51c37df75. Specifically, they are 40 characters long, and are the result of hashing the repository with SHA-1. My idea is pretty simple: make the program write the current commit鈥檚 hash to the log file. Then, given any log file, I can see the commit used to generate it, and go back in the git history to see exactly what my code was doing at that point. Bas...
First seen: 2025-11-19 18:00
Last seen: 2025-11-20 00:01