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

How to put tree into index

From
AGAlexander GQ Gerasiov <gq@cs.msu.su>
Date
Nov 20, 2013, 11:47 UTC
Message-ID
<20131120154714.39fc5202@snail>
Hello there.
I need to realize the following scenario with git.
1. I have repository with tree like this:
dir1/
	file1
	file2
	file3
dir2/
	subdir1/
		some files
2. Current branch is B.
3. I want to get dir1 from branch A, and save it's content on current
branch (B) as dir2/subdir1
>From my point I should do the following
1. Get tree-object sha1 of dir1 from A with git ls-tree
2. Put into index new tree-object with the same sha1/content, but under
the name dir2/subdir1
3. Commit index.

But it doesn't work for me. It works with blob object, but not with tree object.

I tried the following commands:

git ls-tree A dir1 | sed 's#dir1#dir2/subdir1#' | git update-index --index-info

But after this I see in the index not tree-object with mode 040000, but commit-object with mode 160000.

So my question is How to put into index tree-object with known sha1 and given name?

PS I was able to do what I need when copied files, not tree-itself. Just add -r to git ls-tree, and put into index blobs/files, not tree. But I'm interested: is it possible to put tree-object into index?

Next: Matthew Cengia
Message 1 of 3 in “How to put tree into index”
  1. Alexander GQ GerasiovNov 20, 2013
  2. Matthew CengiaNov 20, 2013
  3. Johannes SixtNov 20, 2013

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.