1

I have a git repository that takes up a lot of disk space, so I'm investigating it.

If I have the hash of a tree, how can i see what commits have that tree? The tree-hash in question might be a subdirectory of the commit, not necessarily the 'root' tree of the commit.

Amandasaurus
  • 58,203
  • 71
  • 188
  • 248
  • See [Git - finding a filename from a SHA1](http://stackoverflow.com/q/460331/1256452). Although that's for blobs, the scripts there are easily adapted for finding trees too/instead. – torek Jan 13 '14 at 13:35

1 Answers1

1

If the tree that you have the hash of is the top level tree, then git log --pretty=format:"%H %T" --all | awk -v sha=${SHA} '$2 == sha { print $1 }' will show you what commit(s) had that tree as the commit state. If it's not a top-level tree, though, you'll have to essentially iterate through all the commits on all branches, and recursively list all trees contained in each commit to see if it's among them. Something along these lines (not tested):

while read commit
do
  git ls-tree -rt ${commit}^{tree} | grep "tree ${SHA}" | sed -e "s/^.*$/${commit}/"
done < <(git log --pretty=format:"%H" --all)
twalberg
  • 59,951
  • 11
  • 89
  • 84