iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 23
0
自我挑戰組

Experience of a backend novice系列 第 23

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

  • 分享至 

  • twitterImage
  •  

Day twenty-three

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

Hello everyone. It's Ray.
大家好,我是Ray!

Yesterday we mentioned how Git works when we commit, also, we mentioned blob objects and tree objects.
昨天我們介紹了當我們第二次commit時,Git的實際流程是怎麼樣,同時我們也介紹了blob物件以及tree物件。

  1. What is commit? / Commit是什麼?
  2. What is tag? / Tag是什麼?
  3. What is branch? / Branch是什麼?
  4. What is Head? / Head是什麼?

Let's start from where we were yesterday, there are still something we haven't talked about as above:
延續昨天的進度,我們還有四個東西沒有介紹,如上。

Firstly, what is commit?
首先,commit是什麼?

Still remember what we talked about in previous articles? Blob objects represent the content of files, and tree objects represent the name of files, directory ...etc. And let's go upper, what the heck is commit?
還記得前幾篇的介紹嗎?blob物件就是我們儲存的檔案,tree物件就是檔案的名稱以及目錄等資訊,而在往上,commit呢?

Commit is actually a record. Git make this record with SHA1 and some other mechanism according to when we commit, who make the commit, and what tree objects are at that moment. The record turns out as a checksum with 40 characters. When we checkout the designated commit, this commit will point to corresponding tree objects, and those tree objects will point to corresponding blob objects, so the data will revert to what it was at that commit.
commit其實就是一個紀錄,git會根據我們commit的時間,以及commit的作者,針對我們commit的tree物件以及blob物件生成一個由SHA1產生的40碼的值,當我們使用git checkout切換到該commit時,這個commit會指向當初做這個commit時的tree物件,以及tree物件會指出代表檔案的blob物件,所以我們的檔案會還原到當初做這個commit時的狀態。

And then, what is tag?
接下來說說,什麼是tag?

We already have commits, why do we need tags?
我們都已經有commit了,那為什麼還要有tag?

Actually, if we use git checkout go back to a specific commit, or a tag, in essence, there are no differences. If there is any, that would be to make the version controller eaiser. Tag is actually just a file with 40 characters made with SHA1 according to some other mechanism, which makes this number unique. It serves as an index to the commit we make. Same thing above, it points corresponding commit, and which points to tree objects, and then points to blob objects, and revert the data to what it's supposed to be.
其實如果我們使用git checkout回到一個commit 或一個tag,本質上是沒有多大分別的,如果要說有什麼不同的話,那就是tag可以讓開發者更容易地做版本管控。
我們可以使用commit來管控不同的功能描述,然後使用tag來做版本分割,這樣是不是在管理上會更清楚呢?
tag是一個檔案,檔案裡面會有一串40碼,使用SHA1產生的獨一無二的驗證碼,而它就只是一個索引,把我們tag的commit指出來,再利用該commit去把tree跟blob的物件指出來以回到我們要的檔案狀態。

Simply speaking, when we take a note, sometimes we mark different pages with bookmark stickers, and we could go back to wherever we want with the stickers. This concept is similar to tag in Git.
簡單來說,我們在做筆記時,有些人會使用貼紙在一些我們要特別做紀錄的頁面上貼一張貼紙,日後如果我們想回去的話只要拉一下貼紙就可以回去了,這個概念就相當於git裡面的tag。

So tag is just a tag to Git. When you tag, the file is not going to be copied, and removing it is also not going to delete your files. It just serves as an index, just that simple.
所以tag在git裡面就真的只是一張tag而已,你的檔案不會被複製,撕掉它也不會移除掉你的檔案,他就只是一個指出該檔案紀錄的一個指標,這麼單純。

Let's call it a day guys, see you tomorrow.
太多資訊可能會造成消化不良,我們明天見!


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

尚未有邦友留言

立即登入留言