在本书的git内部章节中,git-scm有一个如何创建git树的示例:
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.
然后他们列出了我可以用来创建树的命令.我的问题是我是否可以在不使用索引(临时区域)的情况下创建树?例如,而不是这样做:
git update-index --add --cacheinfo 100644 83baae618... test.txt
Run Code Online (Sandbox Code Playgroud)
使用这样的东西:
git create tree --add --cacheinfo 100644 83baae618... test.txt
Run Code Online (Sandbox Code Playgroud)
基于Ismail Badawi的anser 更新:
$ echo 'making tree' | git hash-object -w --stdin
07dae42a0730df1cd19b0ac693c6894a02ed6ad0
Run Code Online (Sandbox Code Playgroud)
然后
$ echo -e '100644 blob 07dae42a0730df1cd19b0ac693c6894a02ed6ad0 \maketree.txt' | git mktree
fatal: input format error: 100644 blob 07dae42a0730df1cd19b0ac693c6894a02ed6ad0 \maketree.txt
Run Code Online (Sandbox Code Playgroud)
你可以git mktree像这样使用:
echo -e "100644 blob 83baae618...\ttest.txt" | git mktree
Run Code Online (Sandbox Code Playgroud)
(你需要写echo -e因为文字标签.这是一个shell的东西,而不是一个git的东西).
请注意,这会创建一个仅指向的树83baae618,因此它与您的update-index调用不完全相同,后者会添加到索引(通常已指向其他内容).您可以传递多行git mktree,每行描述一个blob或树.
| 归档时间: |
|
| 查看次数: |
333 次 |
| 最近记录: |