git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Problem creating commits/trees with commit-tree/mktree

From
GBGavin Beatty <gavinbeatty@gmail.com>
Date
Jan 11, 2010, 18:14 UTC
Message-ID
<f6d77fed1001111014g73a06923na05cd14d37968b04@mail.gmail.com>
Hello,

I want to write commits to a branch without touching the index or having a checkout (for a git subcommand I'm writing).

I can create new blobs and trees but can't figure out how to commit a new tree/blob _with_ the old tree.

Currently, I do something a lot like:

objsha=$(echo 'contents' | git hash-object -w --stdin) objtreesha=$(printf "100644 blob $objsha\tfile.txt\000" | git mktree -z) newtreesha=$(printf "040000 tree $objtreesha\ttreefileisin\000" | git mktree -z) echo 'commit msg' | git commit-tree $newtreesha -p $(git rev-parse refs/heads/new)

I get a commit with treefileisin/file.txt. I haven't included the other trees/files so they are gone in this commit. How do I include them? Is commit-tree the wrong tool?

Is there some way to use git ls-tree that I don't know about?
Gavin
-- 
Gavin Beatty

SEMPER UBI SUB UBI
Next: Shawn O. Pearce
Message 1 of 4 in “Problem creating commits/trees with commit-tree/mktree”
  1. Gavin BeattyJan 11, 2010
  2. Shawn O. PearceJan 11, 2010
  3. Avery PennarunJan 11, 2010
  4. Gavin BeattyJan 14, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.