git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Find commit that referenced a blob first
@ 2018-07-19 21:02 Lars Schneider
  2018-07-19 21:19 ` Stefan Beller
  0 siblings, 1 reply; 6+ messages in thread
From: Lars Schneider @ 2018-07-19 21:02 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Jared Murrell

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Find commit that referenced a blob first
  2018-07-19 21:02 Find commit that referenced a blob first Lars Schneider
@ 2018-07-19 21:19 ` Stefan Beller
  2018-07-19 21:45   ` Lars Schneider
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Stefan Beller @ 2018-07-19 21:19 UTC (permalink / raw)
  To: Lars Schneider; +Cc: git, Jeff King, primetheus

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Find commit that referenced a blob first
  2018-07-19 21:19 ` Stefan Beller
@ 2018-07-19 21:45   ` Lars Schneider
  2018-07-19 21:47   ` Jeff King
  2018-07-19 22:38   ` Junio C Hamano
  2 siblings, 0 replies; 6+ messages in thread
From: Lars Schneider @ 2018-07-19 21:45 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git, Jeff King, primetheus


> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Find commit that referenced a blob first
  2018-07-19 21:19 ` Stefan Beller
  2018-07-19 21:45   ` Lars Schneider
@ 2018-07-19 21:47   ` Jeff King
  2018-07-19 22:38   ` Junio C Hamano
  2 siblings, 0 replies; 6+ messages in thread
From: Jeff King @ 2018-07-19 21:47 UTC (permalink / raw)
  To: Stefan Beller; +Cc: Lars Schneider, git, primetheus

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Find commit that referenced a blob first
  2018-07-19 21:19 ` Stefan Beller
  2018-07-19 21:45   ` Lars Schneider
  2018-07-19 21:47   ` Jeff King
@ 2018-07-19 22:38   ` Junio C Hamano
  2018-07-19 22:45     ` Stefan Beller
  2 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2018-07-19 22:38 UTC (permalink / raw)
  To: Stefan Beller; +Cc: Lars Schneider, git, Jeff King, primetheus

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Find commit that referenced a blob first
  2018-07-19 22:38   ` Junio C Hamano
@ 2018-07-19 22:45     ` Stefan Beller
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Beller @ 2018-07-19 22:45 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Lars Schneider, git, Jeff King, primetheus

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?

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-07-19 22:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-19 21:02 Find commit that referenced a blob first Lars Schneider
2018-07-19 21:19 ` Stefan Beller
2018-07-19 21:45   ` Lars Schneider
2018-07-19 21:47   ` Jeff King
2018-07-19 22:38   ` Junio C Hamano
2018-07-19 22:45     ` Stefan Beller

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).