iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 22
0
自我挑戰組

Experience of a backend novice系列 第 22

Git的物件,當我們commit時,究竟發生了什麼事2

Day twenty-two

Git的結構與commit的實際流程2
How is commit made? What’s git’s structure? part 2

In the end of yesterday, we used a simple image to visualize Git's structure and how it works when we commit. Today I'm going to show you that how it works when we make anohter commit.
昨天的最後,我們用簡單的圖表來視覺化git的結構與一個commit的實際流程,今天我們來看看,當我們下了另外一個commit之後,git 會是如何運作的。

At end of yesterday, we've made a commit as photo above:
昨天的最後,如上圖,我們已經完成一個commit。

Now let's add a new file, and use git add to add it into tracking list. Git will create a new blob like image below:
現在我們新增一個檔案,並使用git add將檔案加入追蹤清單,此時git會產生一個新的blob物件,如下圖:

And then we type git commit -am "The second commit", and Git will create a new tree object along with a new commit object.
The newly created object will not only point to newly created blob object, but also old tree object, and the newly created commit object will point to previous commit, and HEAD move forward to new commit as photo below:
接著我們下git commit -am "The second commit",此時git 會產生一個新的tree物件,並且產生一個新的commit物件。
新的tree物件除了指向之前的物件之外,還指向新產生的blob物件,最後新的commit指向前一個commit,然後HEAD往前移,如下圖:

Through the image above, we could see that:
由上圖可以看到:

  1. The newly created tree object not only points to the newly created blob object, but also the old tree object / 新的tree物件除了指向新增的blob物件之外,還指向了已存在的tree物件。

  2. The newly created commit not only point to newly created tree object, but also the previous commit object / 新的commit除了指向新的tree物件之外,也指向了之前的commit物件。

  3. The branch move forward with newly created commit object / Branch往後移,跟著新增的commit跑。

  4. The Head move forward with newly created branch / Head一樣往後移,跟著Branch跑。

Above explained is a wholly process when making a commit, now let's list some questionns as follows:
以上就是一次完整commit的流程動作,那接下來我們列出幾個問題如下:

  1. What is blob? / Blob是什麼?
  2. What is tree? / Tree是什麼?
  3. What is commit? / Commit是什麼?
  4. What is tag? / Tag是什麼?
  5. What is branch? / Branch是什麼?
  6. What is Head? / Head是什麼?

Let's only talk about blob and tree objects today to prevent too much information.
為了避免大家消化不良,今天讓我們先針對Blob跟Tree跟各位解釋。

As shared in my article yesterday, actually Git doesn't care the name or directory or whatever but the content of file. All the information except for content only serves as identifier.
如同昨天的文章跟各位分享的,Git其實並不在意檔案的名稱或是目錄,Git真正在意的,只有檔案的內容,其他的資訊對Git來說都只是一種'辨識'的功用。

Some books say that Blob is the abbreviation of Binary Large object, which indeed has its meaning. However, personally I think it's also meaningful without considering it as an abbreviation.
Blob有些書裡說是binary Large Object的縮寫,當然我個人更傾向記成這個單字的原本意思,1滴,感覺這樣也很傳神啊!

Blob object denotes the content of file, in other words, if you created three files with different names but the same content, Git will only keep one.
Blob: Anything except for content has nothing to do with me.
Blob物件就是我們儲存的檔案'內容',換言之,如果你放了三個不同檔名但內容完全相同的檔案到有安裝Git的資料夾,當你下了git add之後,實際上git只會儲存一份檔案。
blob:檔名目錄那些都跟我一點關係都沒有!

And what teh heck is tree? As mentioned above, tree keeps those blob doesn't want.
那什麼是tree呢? 我們剛剛說的,blob不管的檔名目錄就是tree在記錄啦!

When we commit, tree object will keep the designated file name or additional directory ...etc, and point to corresponding blob objects. Simply speaking, when we used git add, blob objects were already been created, and when we used git commit, Git only pointed those blob out for us.
當我們commit時,tree物件會儲存我們指定的檔名,目錄資訊,並指向相對應的blob物件,簡單來說,當我們使用git add之後,檔案都已經被加到git的資料夾內,而當我們使用git commit時,git只是把這些檔案“指”出來而已!

I hope that what I am going to share today is going to help you with better understanding of Git.
See you tomorrow.
希望今天的文章可以讓大家對git有更深一層的認識!
我們明天見!


上一篇
Git的物件,當我們commit時,究竟發生了什麼事
下一篇
Git的物件,當我們commit時,究竟發生了什麼事3
系列文
Experience of a backend novice30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言