title: Which git commit/branch contains this blob?
body: <p>I am using this script to compute the n largest blops in my repository:</p>
  
  <p><a href="https://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/" rel="nofollow noreferrer">https://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/</a></p>
  
  <p>An example of the output:</p>
  
  <pre><code>54016,13273,0ef462bf57e8c036b00b52d6cc0fd91b2fc2a827 Data/Db.MDF
  30976,8734,3e162c8313995980c8d6fc434c06789373364a47 Tools/connector.dll
  </code></pre>
  
  <p>The two SHAs above are SHAs for the blops. Now I would like to locate the commit/branch that contains those blops. I first tried:</p>
  
  <pre><code>$ git branch -a --contains 3e162c8313995980c8d6fc434c06789373364a47
  error: object 3e162c8313995980c8d6fc434c06789373364a47 is a blob, not a commit
  </code></pre>
  
  <p>As the message says above the SHA is for a blob not a commit. This leads me to: <a href="https://stackoverflow.com/questions/223678/which-commit-has-this-blob">Which commit has this blob?</a></p>
  
  <p>I have created the two scripts from the above post and added those to the root of my repository. But when I run them nothing gets outputted:</p>
  
  <pre><code>MINGW64 /c/tmp/MyRepo (master)
  $ ./blop-to-commit.sh 3e162c8313995980c8d6fc434c06789373364a47
  
  MINGW64 /c/tmp/MyRepo (master)
  </code></pre>
  
  <p>Also tried to run it on a local bare clone of the repository:</p>
  
  <pre><code>MINGW64 /c/tmp/MyRepo.bare (BARE:master)
  $ ./blop-to-commit.sh 3e162c8313995980c8d6fc434c06789373364a47
  
  MINGW64 /c/tmp/MyRepo.bare (BARE:master)
  </code></pre>
  
  <p>Any ideas why I don't get the commit/branch that contained that blop at some point in history?</p>
  
  <p><strong>EDIT/SOLUTION:</strong></p>
  
  <p>Seems I just had to add the --all option to the git log command:</p>
  
  <pre><code>shift
  git log --all "$@" --pretty=format:'%T %h %s' \
  | while read tree commit subject ; do
      if git ls-tree -r $tree | grep -q "$obj_name" ; then
          echo $commit "$subject"
      fi
  done
  </code></pre>
  
  <p>As suggested below:</p>
  
  <pre><code>$ git fsck
  Checking object directories: 100% (256/256), done.
  Checking objects: 100% (100278/100278), done.
  Checking connectivity: 100342, done.
  dangling commit 3f8cd0a581ec694e7371f7e4183e1cad8fa87647
  dangling commit d5c0f41337ae1ef8e5cfbfd4f70077c36d231cf1
  dangling commit b01831f4e6679ef2696a83e6dbaa04eaf6748f85
  dangling commit 82b32531c23202d123f693bba64b040b3247636b
  dangling commit 4fa8ce87c268a7ddb7c4e72d6810f70e197d5812
  dangling commit 3ce38a0b8e5dbb7424a88359bbe0d9130ced34dc
  </code></pre>
  
  <p>I then did:</p>
  
  <pre><code>git reflog expire --expire-unreachable=now --all
  git gc --prune=now
  </code></pre>
  
  <p>But I still don't see corresponding commits for the blobs originally listed.</p>