问题描述
在<$的章节中
您可以使用 git mktree ,如下所示:
echo -e100644 blob 83baae618 ... \ttest.txt| git mktree
<您需要编写 echo -e
$ b
请注意,这会创建一个只指向的树, 83baae618 ,所以它与你的 update-index 调用并不完全相同,这会增加索引(通常已经指向其他东西)。您可以将多行传递给 git mktree ,每行描述一个blob或树。
In the git internals chapter of git-scm book there is an example of how git tree can be created:
Git normally creates a tree by taking the state of your staging area or index and writing a series of tree objects from it. So, to create a tree object, you first have to set up an index by staging some files.
And then they list commands that I can use to create the tree. My question is whether I can create a tree without using index (staging area)? For example instead of doing this:
git update-index --add --cacheinfo 100644 83baae618... test.txt
Use something like this:
git create tree --add --cacheinfo 100644 83baae618... test.txt
Update based on Ismail Badawi's anser:
$ echo 'making tree' | git hash-object -w --stdin 07dae42a0730df1cd19b0ac693c6894a02ed6ad0
and then
$ echo -e '100644 blob 07dae42a0730df1cd19b0ac693c6894a02ed6ad0 \maketree.txt' | git mktree fatal: input format error: 100644 blob 07dae42a0730df1cd19b0ac693c6894a02ed6ad0 \maketree.txt
You can use git mktree, like this:
echo -e "100644 blob 83baae618...\ttest.txt" | git mktree
(You need to write echo -e because of the literal tab. This is a shell thing, not a git thing).
Note this creates a tree that only points to 83baae618, so it's not exactly the same as your update-index invocation, which adds to the index (which typically already points to other things). You can pass multiple lines to git mktree, each line describing one blob or tree.
这篇关于不使用临时区域创建树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!