How to remove an entry with null sha1 in a Git tree
For anyone still having trouble with this, I solved this issue using git-filter-repo:
git filter-repo --path <folder> --invert-paths
filter-repo does not have the same problems that filter-branch has with the null sha1 and is a lot quicker.
See this answer/question: https://stackoverflow.com/a/61544937/1827771
gizmo
Updated on November 26, 2022Comments
-
gizmo over 1 year
I have inherited of a git repository with a null sha1 for a commit entry in a tree, preventing FishEye to index the repository.
$ git fsck Checking object directoriies: 100%(256/256), done. warning in tree db22a67df70dc4ff90ec4cd666da91e9c2cb0d9: contains entries pointing to null sha1 Checking objects: 100% (416532/416532), done. Checking connectivity: 416532, done.
Looking for the given tree give me the following result:
$ git ls-tree db22a6 100644 blob e615f18b55a39f2719112ce209c2505dd92d8e75 .gitignore 100644 blob ac852f06c5a04420356c1d5efca44d9a864e78b0 .project 160000 commit 0000000000000000000000000000000000000000 SomeDirectory 100644 blob 631c17e28026261a2ccf6bc570842cf4af9f181c GoDeploy.bat 100644 blob 40e992ab5c3868af2910135c3ac4610c3646e7f8 pom.xml
Looking in the history, I've found that
SomeDirectory
was initially a git submodule and that the commit that seems to cause the issue is the one that removed both the.gitmodules
andSomeDirectory
. Now, there is a real directory calledSomeDirectory
at the exact same place where the culprit was.
I though I could still try to fix run agit filter-branch
to see what I would end up, but it does not work:$ git filter-branch --force --index-filter \ $ 'git rm --cached --ignore-unmatch SomeDirectory' \ $ --prune-empty --tag-name-filter cat -- --all [... striped out for clarity] Rewrite c571a3ec94e9f84471577bac41ac7375c729ef08 (76/18522)error: cache enttry has null sha1: SomeDirectory fatal: unable to write new index file Could not initialize the index [... striped out for clarity]
What am I supposed to try next, knowing that there is no backup that I'm aware of prior to the commit that causes the issue.
-
gizmo almost 10 yearsdb22a6 is the SHA1 of the tree object, not the faulty commit. Anyway, I tried to do it with c571a3 but without success. It fails to perform the change and mark it as a conflict with the next commit.