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

Re: Raw commands to add object to existing tree

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Aug 21, 2009, 22:49 UTC
Message-ID
<alpine.LFD.2.01.0908211546250.3158@localhost.localdomain>
In-Reply-To
<32541b130908211539ke64bd2bif0aa7cff6bc6ae8f@mail.gmail.com>
On Fri, 21 Aug 2009, Avery Pennarun wrote:
Show 8 quoted lines
> (Warning: untested code follows)
> 
> export GIT_INDEX_FILE=/tmp/my-temp-index
> git read-tree PREVIOUS_COMMIT_OR_TREE_ID
> hash=$(git hash-object NEW_FILE)
> git update-index --cacheinfo "0644 $hash path/of/file/in/tree"
> commitid=$(echo COMMIT MESSAGE | git commit-tree $(git write-tree))
> git update-ref refs/heads/BRANCHNAME $commitid PREVIOUS_COMMIT_OR_TREE_ID

Looks roughly correct, but you need to add a a "-p $PREVIOUS_COMMIT" to that git commit-tree thing. Otherwise the new commit will be a root commit. Which _might_ be what you want, of course, but I kind of expect it wasn't.

And no, I didn't test that either, so there may be other things that need fixing too.

Looking at that thing, I have ugly flashbacks to my git scripts in 2005 ;)
			Linus
Previous: Avery PennarunNext: Avery Pennarun
Message 3 of 4 in “Raw commands to add object to existing tree”
  1. D SundstromAug 21, 2009
  2. Avery PennarunAug 21, 2009
  3. Linus TorvaldsAug 21, 2009
  4. Avery PennarunAug 21, 2009

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.