How to compute the git hash-object of a directory?



Does anyone have an example of using git hash-object on a directory? It works easily enough on a file* but doesn’t work as I’d expect for a directory**

*:  git hash-object c:\somefile.txt
**: git hash-object -t tree c:\somedirectory

When I try to use hash-object with the directory, it complains “fatal: Cannot open ‘C:\someDirectory’: Permission denied”


git hash-object -t tree is expecting the file parameter to be a file that describes the entries in the tree, rather than a directory in the filesystem. I understand from the comment here that this command is expecting a file that describes the tree in a binary format, and that it would be easier to use git mktree for you to create the tree object.

git mktree understands input of the format you get from (for example) git ls-tree HEAD. There is a nice example of constructing a tree from scratch using git hash-object and git mktree in the Git Community Book.

Answered By – Mark Longair

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More