You can get the hash of a tree in a commit by doing:
git rev-parse 'HEAD^{tree}'
And you can get the hash of the tree in the index by doing:
git write-tree
However, in the case you did a sparse checkout by doing
git sparse-checkout init
git sparse-checkout set toto
Then running git write-tree
will still print the hash of the full tree, including the files hidden by the sparse checkout. You can verify that by running git cat-file -p $(git write-tree)
, which will print all the files and directories at the top level.
How to generate the hash of a tree that includes only the files checked out by a sparse checkout?
I found one trick that works, although I don't know what the performance would look like in big repositories: you can
git rm
all the paths from the index, before doinggit add
with only the paths that are checked out.