# Find commit that referenced a blob first

6 messages from 2018-07-19 to 2018-07-19. Participants: Lars Schneider, Stefan Beller, Jeff King, Junio C Hamano.
Thread: https://gitlist.dev/t/48923

## Lars Schneider, 2018-07-19 21:02

Subject: Find commit that referenced a blob first
Message-ID: <C00CED1F-D685-40E5-A5CC-4040BFD82886@gmail.com>
URL: https://gitlist.dev/e/C00CED1F-D685-40E5-A5CC-4040BFD82886%40gmail.com

```
Hi,

I have a blob hash and I would like to know what commit referenced 
this blob first in a given Git repo.

I could iterate through all commits sorted by date (or generation 
number) and then recursively search in the referenced trees until 
I find my blob. I wonder, is this the most efficient way to solve 
my problem? Is there some trick/existing Git command that would 
perform this search more efficiently for large repos?

Thank you,
Lars

```

## Stefan Beller, 2018-07-19 21:19

Subject: Re: Find commit that referenced a blob first
Message-ID: <CAGZ79kbJnyRbeH8yMa=QaqNofA_Ek_SwmH5qRaCaq4cyQ26Kqg@mail.gmail.com>
URL: https://gitlist.dev/e/CAGZ79kbJnyRbeH8yMa%3DQaqNofA_Ek_SwmH5qRaCaq4cyQ26Kqg%40mail.gmail.com
In-Reply-To: <C00CED1F-D685-40E5-A5CC-4040BFD82886@gmail.com>

```
On Thu, Jul 19, 2018 at 2:02 PM Lars Schneider <larsxschneider@gmail.com> wrote:
>
> Hi,
>
> 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

You're welcome,
Stefan

```

## Lars Schneider, 2018-07-19 21:45

Subject: Re: Find commit that referenced a blob first
Message-ID: <E632E745-03C6-4C7F-9B3F-CB46C0D7FCA7@gmail.com>
URL: https://gitlist.dev/e/E632E745-03C6-4C7F-9B3F-CB46C0D7FCA7%40gmail.com
In-Reply-To: <CAGZ79kbJnyRbeH8yMa=QaqNofA_Ek_SwmH5qRaCaq4cyQ26Kqg@mail.gmail.com>

```

> On Jul 19, 2018, at 11:19 PM, Stefan Beller <sbeller@google.com> wrote:
> 
> On Thu, Jul 19, 2018 at 2:02 PM Lars Schneider <larsxschneider@gmail.com> wrote:
>> 
>> Hi,
>> 
>> 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
> 
> You're welcome,
> Stefan

Awesome! Thank you very much :-)

- Lars
```

## Jeff King, 2018-07-19 21:47

Subject: Re: Find commit that referenced a blob first
Message-ID: <20180719214729.GA14323@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20180719214729.GA14323%40sigill.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:

> > 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

```

## Junio C Hamano, 2018-07-19 22:38

Subject: Re: Find commit that referenced a blob first
Message-ID: <xmqqr2jydf6c.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqqr2jydf6c.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <CAGZ79kbJnyRbeH8yMa=QaqNofA_Ek_SwmH5qRaCaq4cyQ26Kqg@mail.gmail.com>

```
Stefan Beller <sbeller@google.com> writes:

> On Thu, Jul 19, 2018 at 2:02 PM Lars Schneider <larsxschneider@gmail.com> wrote:
>>
>> Hi,
>>
>> 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.

You walk from the latest to earlier commit (because there by
definition can be is no reverse pointer from older to newer commit),
and see if it has the blob, and stop when you find one.  Wouldn't it
generally find the most recent use, not the earliest use as Lars
seems to want?

>
> Since
> 644eb60bd01 (builtin/describe.c: describe a blob, 2017-11-15)
> (included first in 2.16.0
>
> You're welcome,
> Stefan

```

## Stefan Beller, 2018-07-19 22:45

Subject: Re: Find commit that referenced a blob first
Message-ID: <CAGZ79kYAQwfHZBSVG6ShVO6FCBKVu3CeKJ7ZLsRGVkfV73WmYA@mail.gmail.com>
URL: https://gitlist.dev/e/CAGZ79kYAQwfHZBSVG6ShVO6FCBKVu3CeKJ7ZLsRGVkfV73WmYA%40mail.gmail.com
In-Reply-To: <xmqqr2jydf6c.fsf@gitster-ct.c.googlers.com>

```
On Thu, Jul 19, 2018 at 3:38 PM Junio C Hamano <gitster@pobox.com> wrote:

> > 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.
>
> You walk from the latest to earlier commit (because there by
> definition can be is no reverse pointer from older to newer commit),

but a "reverse walk from HEAD" produces the commits to us in an order
as if we were walking from earlier to latest?

```
