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

前端 未结 3 762
春和景丽
春和景丽 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条回答
  •  青春惊慌失措
    2020-11-22 00:12

    Here is the answer on how to create empty tree commit even in the case when the repository is not already empty. https://stackoverflow.com/a/14623458/9361507

    But I prefer "empty" to be tag, but not a branch. Simple way is:

    git tag empty $(git hash-object -t tree /dev/null)
    

    Because tag can point to tree-ish directly, without commit. Now to get all the files in the working tree:

    git diff --name-only empty
    

    Or the same with stat:

    git diff --stat empty
    

    All files as diff:

    git diff empty
    

    Check whitespaces in all files:

    git diff --check empty
    

提交回复
热议问题