Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I thought this would be a generally useful thing to have, so I wrote up a little perl script to do it:</p> <pre class="lang-perl prettyprint-override"><code>#!/usr/bin/perl -w use strict; my @commits; my %trees; my $blob; sub blob_in_tree { my $tree = $_[0]; if (defined $trees{$tree}) { return $trees{$tree}; } my $r = 0; open(my $f, "git cat-file -p $tree|") or die $!; while (&lt;$f&gt;) { if (/^\d+ blob (\w+)/ &amp;&amp; $1 eq $blob) { $r = 1; } elsif (/^\d+ tree (\w+)/) { $r = blob_in_tree($1); } last if $r; } close($f); $trees{$tree} = $r; return $r; } sub handle_commit { my $commit = $_[0]; open(my $f, "git cat-file commit $commit|") or die $!; my $tree = &lt;$f&gt;; die unless $tree =~ /^tree (\w+)$/; if (blob_in_tree($1)) { print "$commit\n"; } while (1) { my $parent = &lt;$f&gt;; last unless $parent =~ /^parent (\w+)$/; push @commits, $1; } close($f); } if (!@ARGV) { print STDERR "Usage: git-find-blob blob [head ...]\n"; exit 1; } $blob = $ARGV[0]; if (@ARGV &gt; 1) { foreach (@ARGV) { handle_commit($_); } } else { handle_commit("HEAD"); } while (@commits) { handle_commit(pop @commits); } </code></pre> <p>I'll put this up on github when I get home this evening.</p> <p>Update: It looks like somebody <a href="http://github.com/jwiegley/git-scripts/tree/master/git-find-blob" rel="nofollow noreferrer">already did this</a>. That one uses the same general idea but the details are different and the implementation is <em>much</em> shorter. I don't know which would be faster but performance is probably not a concern here!</p> <p>Update 2: For what it's worth, my implementation is orders of magnitude faster, especially for a large repository. That <code>git ls-tree -r</code> really hurts.</p> <p>Update 3: I should note that my performance comments above apply to the implementation I linked above in the first Update. <a href="https://stackoverflow.com/questions/223678/git-which-commit-has-this-blob#223890">Aristotle's implementation</a> performs comparably to mine. More details in the comments for those who are curious.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload