The situation: I have a tar.gz of a release from a github project but would like to work out which commit this was taken from. It doesn't appear to have been tagged or is it obvious from commit message themselves.
So I can calculate sha1 of the files, but would like to work out which commit these belong to?
Calling git wizards!
Since the git-stored hash doesn't just include the file contents (and, in theory, hash collisions happen anyhow), in order to be really sure you've got the right version of the file you need to compare the contents.
for rev in $(git log --format=%H -- /path/to/file); do
git diff --quiet $x:/path/to/file my-current-file;
if [[ $? -eq 0 ]]; then
echo $x;
fi
done
In English: iterate over the revisions that changed the file, in reverse order. For each such revision, diff the version of the file there with the outside-the-tree file. If the two files are identical, print the revision hash.
If you want to do this for the whole tarball, you can do the same but diff the whole tree instead of a single file (and omit the file path as an argument to git log
) - use whatever tolerant diff options you like.
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