Search code examples
gitgit-plumbing

using git read-tree without a work tree


I am trying to create a commit history using git plumbing commands with a bare repo. I can create commits with a single unnamed tree object containing blobs, but I cannot figure out how to get this unnamed tree object to contain other tree objects.

I tried using git read-tree --prefix=tree_name tree_sha and it tells me: fatal: This operation must be run in a work tree

I tried using git mktree (like it is shown on this page) like this: cat ../info.txt | git mktree

info.txt being a file containing 1 line:

040000 tree aa8c07e1371022a183b011d5d41517ef54780a17    test_tree

and it tells me:

fatal: input format error: 040000 tree aa8c07e1371022a183b011d5d41517ef54780a17    tree_name

Can anyone tell me a way to create and name trees?


Solution

  • You need four spaces instead of one between the hash and test_tree. If it still doesn't work try a tab.

    040000 tree aa8c07e1371022a183b011d5d41517ef54780a17    test_tree