I have code that generates an executable via a makefile. The executable itself generates an output file with data. In the future, when I go back and look at old data that I've kept, I would like to be able to reproduce the data in a reliable and systematic way. In other words, I would need to know an ID number form a repository (GIT) so that I can recover the code, and I would also need to know how I compiled the code and what compiler and flags I used. What is the best way to go about this?

How do I accomplish the same as I've described above but with an old library instead of data, so that I can pick an old library, find out the repository ID number for the code that was used to generate it, and find out the Makefile info used to generate it?