Home > database >  How to find the certain commit of an outdated file?
How to find the certain commit of an outdated file?

Time:08-25

I have a file taken from a repo some time in the distant past. Is there a way to tell what commit this file is related to?

UPDATE: Since the question was closed, I probably was not clear enough. The suggested question linked-to by the mod does not answer my question.

I am well aware of commit history. That's not what I am asking. I am asking to find what was the commit associated with that specific file version. I don't know what changed wrt the previous commit, nor what changed the following commit, so a simple history does not do the trick.

A brute-force check would be to systematically check-out every commit and compare the file in the repo to the outdated copy I have, until I find the matching commit.

CodePudding user response:

git log has a --find-object=<hash> option.

You can compute the hash for that exact version of the file, and ask git what commits added or removed a file with that specific hash :

hash=$(git hash-object that/file)
# note: you can run 'git hash-object' and 'git log --find-object' on
# two different machines
git log --oneline --find-object=$hash --all
  • Related