Can you determine the version of the git file copied from the repo?

I inherited an Xcode project that uses code from the CocoaAsyncSocket project (available on GitHub). The files (AsyncSocket.m / h) were copied to the Xcode project, so I don't have a git history.

I need to find which version of the files I have. Is there a way to compare my files (assuming they have not been edited) with the repo history to find out what message I have?

+4
source share
2 answers

First compute the hash of your file with git hash-object .
You can then use git ls-tree to list the hashes of each commit in question.

I would use something like this:

 file=AsyncSocket.m hash=$(git hash-object $file) for i in $(git rev-list HEAD -- $file); do git ls-tree $i|grep -q $hash && echo $i done|xargs -l git log -1 --oneline --decorate 
+4
source

This is not an easy way that I know about, especially if a particular version of this file is displayed in several versions of a common project (i.e. this file has not changed between versions).

However, you can git hash-object -t blob AsyncSocket.h to get the hash for this file, and then use git ls-tree -r <some_version_tag>^{tree} | grep <hash> git ls-tree -r <some_version_tag>^{tree} | grep <hash> several times for different version tags to find out which versions are included in this file. Of course, if it was modified in any case, since it was "imported", this will not work if you do not get access to the original copy ...

+2
source

Source: https://habr.com/ru/post/1479963/


All Articles