git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: how to determine version of binary

From
Sitaram Chamarty <sitaramc@gmail.com>
Date
May 5, 2012, 11:43 UTC
Message-ID
<20120505114306.GA1498@sita-lt.atc.tcs.com>
In-Reply-To
<jo2jtd$m6c$1@dough.gmane.org>
On Sat, May 5, 2012 at 12:42 PM, Neal Kreitzinger <nkreitzinger@gmail.com> wrote:
> Scenario:  I detect a binary file that is 'dirty'.  I don't know how it got
> there.  However, I know it came from a git repo.  So I calculate the sha1 of
> the binary.  What is the git command to determine which commit that binary

make sure you are using 'git hash-object' to compute the sha, not the system supplied 'sha1sum' or eqvt.

> version first appeared in?  And the last commit that binary appeared in?

Unless it is a frequent need, I would just use git log's --raw option to search for the first 7 digits of the SHA you found above.

For example, a very quick one (which does not count odd situations like the same file appearing multiple times or on other branches, for instance) is:

    git log --raw | less +/$SHA

You'll want a line where the SHA appears as the second SHA, not the first one (in case a later commit changed the file it would also appear as the first sha). Example, I'm looking for "14136eb", so I type in

    git log --raw '--format=%n%ncommit: %h subject: %s' | egrep commit\|14136eb | grep -B 1 14136eb
The output I get back is:
    commit: 1cf062f subject: ACCESS_CHECK split into ACCESS_1 and ACCESS_2; docs updated
    :100755 100755 14136eb... 2a57e2d... M	src/gitolite-shell
    --
    commit: b391000 subject: POST_GIT triggers get 4 more arguments
    :100755 100755 20f4e5d... 14136eb... M	src/gitolite-shell

So the commit that introduced this version of this file is b391000 (1cf062f is a later one where this file got changed to something else).

Previous: Jeff King
Message 5 of 5 in “how to determine version of binary”
  1. Neal KreitzingerMay 5, 2012
  2. Jeff KingMay 5, 2012
  3. Neal KreitzingerMay 5, 2012
  4. Jeff KingMay 6, 2012
  5. Sitaram ChamartyMay 5, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.