Reputation: 324
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?
Upvotes: 2
Views: 436
Reputation: 153
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
Upvotes: 1
Reputation: 40710
I assume a tree with hash aa8c07e1371022a183b011d5d41517ef54780a17
already exists in your repo? If not, git mktree
will fail. Also, do you have a trailing newline in info.txt
? My reading of the docs suggests this is also required.
I have successfully used git mktree
like this:
$ cat tree.txt
040000 tree 4d5fcadc293a348e88f777dc0920f11e7d71441c foo
$ git mktree < tree.txt
0a7f38a609340d0b8eede2f6debf8bad4191738f
Where the first two spaces are spaces, and the third is a tab, and with a trailing newline. If in doubt, run git ls-tree
and examine its output, possibly with xxd
.
Upvotes: 0