不使用临时区域创建树 [英] create tree without using staging area

查看:119
本文介绍了不使用临时区域创建树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在<$的 git内部章节中



git正常通过获取暂存区域或索引的状态并从中创建一系列树对象来创建树。因此,要创建树对象,首先必须通过暂存某些文件来设置索引。

然后他们列出命令可以用来创建树。我的问题是我是否可以在不使用索引(暂存区)的情况下创建一棵树?例如,而不是这样做:

pre $ g $ update-index --add --cacheinfo 100644 83baae618 ... test.txt

使用如下所示:

  git create tree --add --cacheinfo 100644 83baae618 ... test.txt 



更新基于伊斯梅尔Badawi的安塞尔:

  git hash-object -w --stdin 
07dae42a0730df1cd19b0ac693c6894a02ed6ad0

然后

  $ echo -e'100644 blob 07dae42a0730df1cd19b0ac693c6894a02ed6ad0 \maketree.txt'| git mktree 
fatal:输入格式错误:100644 blob 07dae42a0730df1cd19b0ac693c6894a02ed6ad0 \maketree.txt


解决方案

您可以使用 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.

这篇关于不使用临时区域创建树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆