Is git's semi-secret empty tree object reliable, and why is there not a symbolic name for it?

前端 未结 3 801
春和景丽
春和景丽 2020-11-21 23:37

Git has a well-known, or at least sort-of-well-known, empty tree whose SHA1 is:

4b825dc642cb6eb9a060e54bf8d69288fbee4904

(you can see this in

3条回答
  •  萌比男神i
    2020-11-22 00:21

    I wrote up a blog post with two different ways of finding the hash: http://colinschimmelfing.com/blog/gits-empty-tree/

    If it were to ever change for some reason, you could use the two ways below to find it. However, I would feel pretty confident using the hash in .bashrc aliases, etc., and I don't think it will change anytime soon. At the very least it would probably be a major release of git.

    The two ways are:

    1. The answer above: git hash-object -t tree --stdin < /dev/null
    2. Simply initing an empty repo and then running git write-tree in that new repo - the hash will be output by git write-tree.

提交回复
热议问题