title: How to fix a git repository with lots of dangling objects, that fails git gc --prune=now with fatal: bad object:
body: <p>I have a repository whose remote is on bitbucket. At certain point I pushed a branch to server, and by mistake asked to push all local tags.</p>
  <p>The action failed after some time with an error (cannot recall exactly - but I think I was not allowed to change tags on the server).</p>
  <p>However - since then I have these problems.</p>
  <ol>
  <li><p>lots (~130) of dangling blobs, commits and tags</p>
  </li>
  <li><p>Any attempt to rid of these &quot;dangling&quot; objects - fails with lots of errors, all pointing to one specific &quot;bad object&quot;</p>
  <pre><code> mini-mac7:myRepo $ git fsck
   Checking object directories: 100% (256/256), done.
   Checking objects: 100% (16253/16253), done.
   broken link from  commit c521a9214898aac031831d97e6a8329342b788c4
                 to  commit a2df338e00be26da2f0b84543668ef29b52df5c3
   broken link from  commit 19f55b6374e7adcc42046821c1659bb47df933a8
                 to  commit 0d862ff1507038edf4c26129abcc11ce8c00bef3
   dangling blob ab0129187ed300114d5d34501add4dc05feaeee0
   dangling commit 5a04331eb72123423888a4fac9922355588f138f
   dangling commit 350da8fc761b2b41d923ccad97cf77e320b0cf34
   dangling commit 8c0e4e66c891f4bffc23c1ee35f4d5eaca2bdb78
   dangling tag 9611c319d012589ea451ce56495f4c9673292615
   .
   . (130 more dangling objects... blobs commits and tags)
   .
   mini-mac7:myRepo $ 
  </code></pre>
  </li>
  </ol>
  <p>and</p>
  <pre><code>mini-mac7:itx-mac-agent-broken $ git gc
  error: Could not read a2df338e00be26da2f0b84543668ef29b52df5c3
  error: Could not read a2df338e00be26da2f0b84543668ef29b52df5c3
  error: Could not read a2df338e00be26da2f0b84543668ef29b52df5c3
  .
  . (40 more times - same object)
  .
  error: Could not read a2df338e00be26da2f0b84543668ef29b52df5c3
  fatal: bad object a2df338e00be26da2f0b84543668ef29b52df5c3
  fatal: failed to run repack
  mini-mac7:itx-mac-agent-broken $ 
  </code></pre>
  <p>Can anyone please help me revive this repo? First off --- how to fix the 'bad object' issue?  I already tried <code>fetching --all</code> from remote, <code>deleting .git/objects/96/11c319d012589ea451ce56495f4c9673292615</code> directly (only few actually existed, but when rm'ed --- the dangling objects did not disappear.</p>
  <p>This repo is important - I already cloned it anew from server, but lots of local stashes and branches there contain work that I need. any attempt to pull/fetch etc. fails with strange errors because of these bad and dangling objects.</p>