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