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

Re: Find commit that referenced a blob first

From
Jeff King <peff@peff.net>
Date
Jul 19, 2018, 21:47 UTC
Message-ID
<20180719214729.GA14323@sigill.intra.peff.net>
In-Reply-To
<CAGZ79kbJnyRbeH8yMa=QaqNofA_Ek_SwmH5qRaCaq4cyQ26Kqg@mail.gmail.com>
On Thu, Jul 19, 2018 at 02:19:34PM -0700, Stefan Beller wrote:
Show 14 quoted lines
> > I have a blob hash and I would like to know what commit referenced
> > this blob first in a given Git repo.
> 
> git describe <blob>
> 
> If the given object refers to a blob, it will be described as
> <commit-ish>:<path>,
> such that the blob can be found at <path> in the <commit-ish>, which itself
> describes the first commit in which this blob occurs in a reverse
> revision walk from HEAD.
> 
> Since
> 644eb60bd01 (builtin/describe.c: describe a blob, 2017-11-15)
> (included first in 2.16.0
Hmm.
  $ git describe cfbc47ee2d
  fatal: No tags can describe '83adac3c57ad8cd2c8d44b525414b949950e316d'.
  Try --always, or create some tags.
  $ git describe --always cfbc47ee2d
  83adac3c57:checkout-cache.c

That first output confused me for a moment. We can't produce a nice descriptive name for the commit in question, so we punt on the whole thing.

Anyway. I have found your diff --find-object to be more useful in practice. I.e.:

  git log --find-object=cfbc47ee2d

because I usually care less about a succinct name, and more about digging into the history (so adding "-p", etc).

-Peff
Previous: Lars SchneiderNext: Junio C Hamano
Message 4 of 6 in “Find commit that referenced a blob first”
  1. Lars SchneiderJul 19, 2018
  2. Stefan BellerJul 19, 2018
  3. Lars SchneiderJul 19, 2018
  4. Jeff KingJul 19, 2018
  5. Junio C HamanoJul 19, 2018
  6. Stefan BellerJul 19, 2018

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.