Mihai Terente
Mihai Terente

Reputation: 141

How to find the commit hash that introduced a given tree?

I have a broken tree with the hash given by

$ git fsck
Checking object directories: 100% (256/256), done.
warning in tree <tree-hash>: nullSha1: contains entries pointing to null sha1

and I want to find the commit that introduced it. I know I can find that info if I try to filter the branch with, e.g.:

$ git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch <my_broken_subdir>' --prune-empty --tag-name-filter cat -- --all
...
Rewrite <commit_hash> error:
    cache entry has null sha1: <my_broken_subdir>

However, I have a long history project and running git-filter would take too long.

UPDATE

Actually, the tree is broken by that it contains a null sha1. Therefore, git bisect won't work, since in any commit I check out, running

 git fsck

would always give me the

warning in tree <tree-hash>: nullSha1: contains entries pointing to null sha1

Upvotes: 2

Views: 128

Answers (1)

Mark Adelsberger
Mark Adelsberger

Reputation: 45649

In general, trying to find a tree via the commits doesn't sound like fun, since the "broken" TREE could be anywhere in the TREE hierarchy of any given commit. It sounds like maybe you know the corresponding directory path, which would simplify things a little, but that still sounds like a pretty involved bit of custom scripting.

It might be simpler to use git bisect, with git fsck (looking for the error) as your test for each commit.

Upvotes: 1

Related Questions