2014-12-03 57 views
2

git-scm書的git internals章有怎樣的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 

使用這樣的事情:

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

更新基於司馬義·巴達維的雁:

$ echo 'making tree' | git hash-object -w --stdin 
07dae42a0730df1cd19b0ac693c6894a02ed6ad0 

然後

$ echo -e '100644 blob 07dae42a0730df1cd19b0ac693c6894a02ed6ad0 \maketree.txt' | git mktree 
fatal: input format error: 100644 blob 07dae42a0730df1cd19b0ac693c6894a02ed6ad0 \maketree.txt 
+1

'git mktree'做到這一點 – 2014-12-03 18:46:30

回答

5

您可以使用git mktree,像這樣:

echo -e "100644 blob 83baae618...\ttest.txt" | git mktree 

(你需要寫echo -e因爲文字標籤。這是一個shell的東西,而不是一個混帳的東西)。

請注意,這會創建一棵只指向83baae618的樹,因此它與您的update-index調用不完全相同,這會增加索引(通常已指向其他內容)。您可以將多行傳遞給git mktree,每行描述一個Blob或樹。

+0

謝謝,我試過解決方案,但收到了'輸入格式錯誤'。請看我的空白 – 2014-12-04 09:27:30

+1

@Maximus SHA之後需要一個標籤('\ t'),而不是空格。 '07dae42a0730df1cd19b0ac693c6894a02ed6ad0 \ tmaketree.txt' – 2014-12-04 15:40:05

+0

是的,就是這樣,非常感謝!最好! – 2014-12-04 16:19:47