1

Why am I doing this? There is a folder in separate repository that I want to sync with in simplest possible way.

Based on Git Internals Git Objects chapter I was under impression that folders are just subtrees in git. And assumed that it would be possible to create directory that points to already existing tree.

This is what I've tried:

git update-index --add --cacheinfo 040000 b5fd8e9305 rc

b5fd8e9305 is id of tree. This approach only created empty directory. So the question would be: is it possible to add subtree to tee using git update-cache command?


I've also tried method described in Git subtree merging: low level plumbing article. It works fine, though there is still question why update-index did not work as I expected.

aisbaa
  • 9,867
  • 6
  • 33
  • 48

1 Answers1

1

While tree objects can contain more trees, the index is special, and normally has no (references to) tree objects in it.

It is possible to shove trees into it but they do not behave well (they can magically change into gitlink entries).

When git makes a new commit from an index, it constructs each new tree object on the fly. That is, the index contains the IDs (SHA-1s) of blobs already added to the repository by this point, and the path names under which they should be retained; and git commit—or more precisely, git write-tree—constructs the set of trees needed based on the path names (and +x or -x mode bit) in the index. The commit code can then make the commit itself, which refers to the top-level tree.

(The bottom line, as it were, is that you need to update the index with each blob ID, rather than with the tree.)

Community
  • 1
  • 1
torek
  • 448,244
  • 59
  • 642
  • 775