I have a problem very similar than How to remove an entry with null sha1 in a Git tree but in my case I've several commits.
My local and remote repos has the problem, git let push this branch and break the remote too.
I did try hvd's 2 the solution but always got:
git filter-branch
fatal: replace depth too high for object ...
Hope some one may help me :'(
My steeps:
$ 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.
$ git ls-tree 4bfdd5d1766a16f49223df9b58052d58c164ce7e
160000 commit 0000000000000000000000000000000000000000 angular-file-upload
100644 blob 1f342d6ae3679463acde48c907fcfedfc0c8e06d directives.js
040000 tree 459845516b97c511d8fb032188c3aea236bc50fc dis
This offending file was a sub-module that was created and moved to another folder, the new folder is app/components/angular-file-upload
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
Then, I do apply the steeps mentioned in 1
OLDTREE=$(git fsck 2>&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} ==> ${NEWCOMMIT}"
echo git replace
git replace ${OLDCOMMIT} ${NEWCOMMIT}
echo git filter-branch
git filter-branch
done
I got the same result if git filter-branch
is inside or outside the for loop
. I tried in reverse order too.
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.