title: how to remove several entries with null sha1 in a git-tree
body: <p>I have a problem very similar than <a href="https://stackoverflow.com/questions/24183847/how-to-remove-an-entry-with-null-sha1-in-a-git-tree">How to remove an entry with null sha1 in a Git tree</a> but in my case I've several commits.</p>
  
  <p>My local and remote repos has the problem, git let push this branch and break the remote too.</p>
  
  <p>I did try hvd's <a href="https://stackoverflow.com/users/743382/hvd">2</a> the solution but always got:</p>
  
  <p><code>git filter-branch
  fatal: replace depth too high for object ...
  </code></p>
  
  <p>Hope some one may help me :'(</p>
  
  <p>My steeps:</p>
  
  <p><code>$ git fsck
  Checking object directories: 100% (256/256), done.
  warning in tree 4bfdd5d1766a16f49223df9b58052d58c164ce7e: contains entries pointing to null sha1
  Checking objects: 100% (668/668), done.</code></p>
  
  <p><code>$ git ls-tree 4bfdd5d1766a16f49223df9b58052d58c164ce7e
  160000 commit 0000000000000000000000000000000000000000  angular-file-upload
  100644 blob 1f342d6ae3679463acde48c907fcfedfc0c8e06d    directives.js
  040000 tree 459845516b97c511d8fb032188c3aea236bc50fc    dis</code></p>
  
  <p>This offending file was a sub-module that was created and moved to another folder, the new folder is <code>app/components/angular-file-upload</code></p>
  
  <p><code>UNWANTED=app/components/angular-file-upload
  git filter-branch --force --index-filter \
   "git rm --cached --ignore-unmatch ${UNWANTED}" \
   --prune-empty --tag-name-filter cat -- --all
  Rewrite 4d2648d9731df59f7f07f501d2649d389447ee6e (69/77)warning: cache entry has null sha1: app/components/angular-file-upload
  rm 'app/components/angular-file-upload'
  Rewrite ef6bf29a874aa8f5998ca47aa2a949c9ac6758e2 (70/77)warning: cache entry has null sha1: app/components/angular-file-upload
  rm 'app/components/angular-file-upload'
  Rewrite c705dba42015610f88defff0822128a5a59df66c (71/77)warning: cache entry has null sha1: app/components/angular-file-upload
  rm 'app/components/angular-file-upload'
  Rewrite 257d74bc3ea3cedb8a57d0db00c17d36a33ff161 (72/77)warning: cache entry has null sha1: app/components/angular-file-upload
  rm 'app/components/angular-file-upload'
  Rewrite 5102c579bd5a4c6611b9f0a2cff891a9a168167e (73/77)warning: cache entry has null sha1: app/components/angular-file-upload
  rm 'app/components/angular-file-upload'
  Rewrite 9911dd15073338ed0caae7cf05f684df51dcbedc (74/77)warning: cache entry has null sha1: app/components/angular-file-upload
  rm 'app/components/angular-file-upload'
  Rewrite 49a254a141545dd703dec5b42ad4cb01bba2c391 (75/77)warning: cache entry has null sha1: app/components/angular-file-upload
  rm 'app/components/angular-file-upload'
  Rewrite 43ec8558e9bf96f12e7f82c067f791420118c6aa (76/77)warning: cache entry has null sha1: app/components/angular-file-upload
  rm 'app/components/angular-file-upload'
  Rewrite ef4cae4b590d569eb2d599cbe492f900da56f507 (77/77)warning: cache entry has null sha1: app/components/angular-file-upload
  rm 'app/components/angular-file-upload'
  WARNING: Ref 'refs/heads/master' is unchanged
  WARNING: Ref 'refs/remotes/origin/master' is unchanged
  Ref 'refs/remotes/origin/UploadAds' was rewritten
  WARNING: Ref 'refs/remotes/origin/master' is unchanged
  WARNING: Ref 'refs/remotes/origin/qa' is unchanged</code></p>
  
  <p>Then, I do apply the steeps mentioned in <a href="https://stackoverflow.com/questions/24183847/how-to-remove-an-entry-with-null-sha1-in-a-git-tree">1</a></p>
  
  <p><code>OLDTREE=$(git fsck 2&gt;&amp;1|
   sed -nre  's/warning in tree (.*): contains entries pointing to null sha1/\1/p')
  COMMITS='4d2648d9731df59f7f07f501d2649d389447ee6e
  ef6bf29a874aa8f5998ca47aa2a949c9ac6758e2
  c705dba42015610f88defff0822128a5a59df66c
  257d74bc3ea3cedb8a57d0db00c17d36a33ff161
  5102c579bd5a4c6611b9f0a2cff891a9a168167e
  9911dd15073338ed0caae7cf05f684df51dcbedc
  49a254a141545dd703dec5b42ad4cb01bba2c391
  43ec8558e9bf96f12e7f82c067f791420118c6aa
  ef4cae4b590d569eb2d599cbe492f900da56f507'
  NEWTREE=$(git ls-tree ${OLDTREE} |
   sed -e '/0\{40\}/d' |
   git mktree)
  echo NEWTREE=${NEWTREE}
  for OLDCOMMIT in ${COMMITS}
  do
      NEWCOMMIT=$(git cat-file commit $OLDCOMMIT | sed 's/$OLDTREE/$NEWTREE/' | git hash-object -t commit -w --stdin) 
      echo "${OLDCOMMIT} ==&gt; ${NEWCOMMIT}"
      echo git replace
      git replace ${OLDCOMMIT} ${NEWCOMMIT}
      echo git filter-branch
      git filter-branch
  done
  </code> </p>
  
  <p>I got the same result if <code>git filter-branch</code> is inside or outside the <code>for loop</code>. I tried in reverse order too.</p>
  
  <p>SOLVED: Git reports this error solving problematic tree and other other fatal errors but after checkout a branch and then moved from this tree all works perfect. </p>