Build a tree by hand from blob SHAs.
Plumbing that builds a tree object from a flat listing of entries on stdin and prints the resulting tree SHA. It is the inverse of ls-tree and the way to assemble trees without touching the index.
Hand it the lines ls-tree would have printed and it gives you back a tree SHA. Combine with hash-object and commit-tree to fabricate a commit entirely server-side, with no working tree at all.
git mktree [-z] [--missing] [--batch] < entries.in
# entry format per line:
# <mode> SP <type> SP <sha> TAB <name>
# e.g. 100644 blob a1b2c3...\tREADME.md
# prints: <tree-sha>| Flag | What it does |
|---|---|
-z | NUL-terminate input records instead of LF (safe for weird filenames). |
--missing | Allow referenced objects to be absent from the ODB. |
--batch | Read multiple trees separated by blank lines; emit one SHA per tree. |
(stdin) | Lines must be sorted as Git expects; otherwise the resulting tree differs. |
printf '100644 blob %s\tREADME.md\n' "$(git hash-object -w README.md)" | git mktreegit ls-tree HEAD | git mktree # should reprint the same SHA as HEAD^{tree}cat trees.in | git mktree --batch # blank lines separate treestree=$(git ls-tree HEAD | git mktree) && c=$(echo msg | git commit-tree "$tree" -p HEAD) && git update-ref refs/heads/auto "$c"Hit each option, then Check answers. Score is recorded; Next is always open.