{"thread":{"id":"22171","subject":"Problem creating commits/trees with commit-tree/mktree","startedAt":"2010-01-11T18:14:46Z","lastAt":"2010-01-14T23:18:00Z","messageCount":4,"participants":["Gavin Beatty","Shawn O. Pearce","Avery Pennarun"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"131300","messageId":"f6d77fed1001111014g73a06923na05cd14d37968b04@mail.gmail.com","threadId":"22171","inReplyTo":null,"subject":"Problem creating commits/trees with commit-tree/mktree","fromName":"Gavin Beatty","fromEmail":"gavinbeatty@gmail.com","sentAt":"2010-01-11T18:14:46Z","receivedAt":"2010-01-11T18:14:46Z","isPatch":false,"sender":{"key":"gavinbeatty@gmail.com","avatar":null},"body":"Hello,\n\nI want to write commits to a branch without touching the index or\nhaving a checkout (for a git subcommand I'm writing).\n\nI can create new blobs and trees but can't figure out how to commit a\nnew tree/blob _with_ the old tree.\n\nCurrently, I do something a lot like:\n\nobjsha=$(echo 'contents' | git hash-object -w --stdin)\nobjtreesha=$(printf \"100644 blob $objsha\\tfile.txt\\000\" | git mktree -z)\nnewtreesha=$(printf \"040000 tree $objtreesha\\ttreefileisin\\000\" | git mktree -z)\necho 'commit msg' | git commit-tree $newtreesha -p $(git rev-parse\nrefs/heads/new)\n\nI get a commit with treefileisin/file.txt. I haven't included the\nother trees/files so they are gone in this commit. How do I include\nthem? Is commit-tree the wrong tool?\n\nIs there some way to use git ls-tree that I don't know about?\n\nGavin\n\n-- \nGavin Beatty\n\nSEMPER UBI SUB UBI\n"},{"id":"131301","messageId":"20100111181712.GQ32155@spearce.org","threadId":"22171","inReplyTo":"f6d77fed1001111014g73a06923na05cd14d37968b04@mail.gmail.com","subject":"Re: Problem creating commits/trees with commit-tree/mktree","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2010-01-11T18:17:12Z","receivedAt":"2010-01-11T18:17:12Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Gavin Beatty <gavinbeatty@gmail.com> wrote:\n> I want to write commits to a branch without touching the index or\n> having a checkout (for a git subcommand I'm writing).\n> \n> I can create new blobs and trees but can't figure out how to commit a\n> new tree/blob _with_ the old tree.\n> \n> Currently, I do something a lot like:\n> \n> objsha=$(echo 'contents' | git hash-object -w --stdin)\n> objtreesha=$(printf \"100644 blob $objsha\\tfile.txt\\000\" | git mktree -z)\n> newtreesha=$(printf \"040000 tree $objtreesha\\ttreefileisin\\000\" | git mktree -z)\n\nYou aren't feeding in the old tree contents as part of this command.\n\nIf you are really doing this via a script, you should look at\ngit-fast-import.  Its faster, and its language better supports\nthis notion of editing an existing tree.\n\n-- \nShawn.\n"},{"id":"131302","messageId":"32541b131001111038m3dacaf72sc12f24aba8c60e@mail.gmail.com","threadId":"22171","inReplyTo":"f6d77fed1001111014g73a06923na05cd14d37968b04@mail.gmail.com","subject":"Re: Problem creating commits/trees with commit-tree/mktree","fromName":"Avery Pennarun","fromEmail":"apenwarr@gmail.com","sentAt":"2010-01-11T18:38:02Z","receivedAt":"2010-01-11T18:38:02Z","isPatch":false,"sender":{"key":"apenwarr@gmail.com","avatar":"https://avatars.githubusercontent.com/u/20592?v=4"},"body":"On Mon, Jan 11, 2010 at 1:14 PM, Gavin Beatty <gavinbeatty@gmail.com> wrote:\n> I can create new blobs and trees but can't figure out how to commit a\n> new tree/blob _with_ the old tree.\n[...]\n> I get a commit with treefileisin/file.txt. I haven't included the\n> other trees/files so they are gone in this commit. How do I include\n> them? Is commit-tree the wrong tool?\n\nWhen I'm doing similar things, I often prefer just using a temporary\ngit index file to keep track of my intermediate trees.  Just set\nGIT_INDEX_FILE to point at a temporary file; then you can use\ngit-read-tree to read in an old tree, and git-update-index\n(particularly with the --stdin flag) to update it.  Then you can use\ngit-write-tree to convert the temporary index into a real tree object.\n\nHave fun,\n\nAvery\n"},{"id":"131688","messageId":"f6d77fed1001141518l22987752x5a1c1e84cb68b677@mail.gmail.com","threadId":"22171","inReplyTo":"32541b131001111038m3dacaf72sc12f24aba8c60e@mail.gmail.com","subject":"Re: Problem creating commits/trees with commit-tree/mktree","fromName":"Gavin Beatty","fromEmail":"gavinbeatty@gmail.com","sentAt":"2010-01-14T23:18:00Z","receivedAt":"2010-01-14T23:18:00Z","isPatch":false,"sender":{"key":"gavinbeatty@gmail.com","avatar":null},"body":"On Mon, Jan 11, 2010 at 19:38, Avery Pennarun <apenwarr@gmail.com> wrote:\n> When I'm doing similar things, I often prefer just using a temporary\n> git index file to keep track of my intermediate trees.  Just set\n> GIT_INDEX_FILE to point at a temporary file; then you can use\n> git-read-tree to read in an old tree, and git-update-index\n> (particularly with the --stdin flag) to update it.  Then you can use\n> git-write-tree to convert the temporary index into a real tree object.\n\nYour suggestion works well.  git update-index --info-only -z\n--index-info takes ls-tree -r -z style format and pre-existing\nobjects: just as I wanted.\n\nThanks, git-fast-import was too much for the quite simple git-related\ncode I need.\n\n-- \nGavin Beatty\n\nSEMPER UBI SUB UBI\n"}]}