2010-04-27 106 views
-1

編輯:如果你downvote我的問題有一個體面的說爲什麼。Git如何知道將哪個索引blob添加到樹中?

Pro Git Ch9的作者說:

通常Git根據你的暫存區域或索引的狀態,並從它上面書寫樹對象創建樹。

我的問題是如何混帳知道兩個consequitive索引條目從創建樹對象?

例如(隨機數的意思是40字符SHA1的 - 我只是做舉起手來):

$ echo 'First change' > one.txt 
$ git add one.txt 
$ find .git/objects -type f 
.git/objects/1f/755a7fffe4 //first index entry 

$ echo 'Second change' > one.txt 
$ git add one.txt 
$ find .git/objects -type f 
.git/objects/2d/234asdf2 //second index entry 

$ git commit -a -m "Initial commit" 
$ git cat-file master^{tree} 
100644 blob 2d234asdf2 one.txt //How did it know not to take 1f755?? 

是否只看BLOB時間戳? 另外 - 創建第一個blob會發生什麼 - 沒有人引用它。它會被摧毀還是被遺忘?

+1

你的git有一些非常錯誤的地方。首先,你在blob上添加'one.txt'和你的對象數據庫增益,然後添加(可能已經存在的)'two.txt',並且你的對象數據庫中只有一個blob,它會丟失對應於'one .txt'。此外,您的blob條目沒有正確的ID。你使用的是什麼版本的git? – 2010-04-27 14:36:16

+0

「git add two.txt」你的意思是「one.txt」? – Thilo 2010-04-27 14:39:24

+0

@Thilo:Yah我的意思是one.txt改變了它。對不起@Charles - 錯字。忽略我製作的ID :-) – drozzy 2010-04-27 16:12:22

回答

2
  1.  
    $ echo 'First change' > one.txt 
    $ git add one.txt 
    $ find .git/objects -type f 
    .git/objects/1f/755a7fffe4... # first index entry (repository database) 
    $ git ls-files --cached --stage --exclude-standard one.txt 
    100644 1f755a7fffe4... 0  one.txt # in 'the index' 
    
  2.  
    $ echo 'Second change' > one.txt 
    $ git add one.txt 
    $ find .git/objects -type f 
    .git/objects/2d/234asdf2...  # second index entry (repository database) 
    $ git ls-files --cached --stage --exclude-standard one.txt 
    100644 2d234asdf2... 0  one.txt  # in 'the index' 
    
  3.  
    $ git commit -a -m "Initial commit" 
    $ git cat-file -p master^{tree} 
    100644 blob 2d234asdf2... one.txt # the one from 'the index' 
    
  4. 「混帳氣相色譜法」 將修剪(刪除)寬鬆的懸空對象.git/objects/1f/755a7fffe4... (僅在出於安全原因延遲之後)。

+0

因此,它只保留最後一個「添加」blob索引? – drozzy 2010-04-27 18:35:45

+0

@drozzy:索引引用LAST「added」blob,git-commit提取索引描述的狀態。 – 2010-04-27 23:04:23

+0

有沒有證據呢? :-)最後你的意思是 - 按時間順序排列最後?如果我將時鐘倒退...... – drozzy 2010-04-27 23:24:37

1

git從文件.git/index創建提交樹,索引存儲當前樹和所有相關信息。您在.git/objects/…看到的是你的文件one.txt的實際BLOB對象的,而不是索引對象

+0

是的,我知道。但是,它如何知道不是第一次使用SECOND?是否有指向索引中最新的blob的指針? 我的意思是當你添加文件時沒有創建TREE對象。 – drozzy 2010-04-27 18:34:40

相關問題