If you only have a file (only contains text data), how can you determine which commit in history it maps to?
This is useful for finding a version of a project when someone has ripped a subset of the files out of the repository and dumped them somewhere.
1) Iterate through all the objects in the repository (.git/objects/*), diff each file (using git cat-file) with your given file
2) When you have found the SHA of the object that matches the input file, find the commit containing that file's SHA. Iterate through all commits and use git ls-tree | grep to find which commit contains the object.
I consolidated this solution into a simple, easy-to-run script here: https://gist.github.com/themattman/20ec6da84304740972e057c22b15c0ee
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With