官术网_书友最值得收藏!

How references work

So, every time we make a commit to a branch, the reference that identifies that branch will move accordingly to always stay associated with the tip commit.

But how will Git handle this feature? Let's go back to putting the nose again in the .git folder:

[5] ~/grocery (master)
$ ll .git/
total 21
drwxr-xr-x 1 san 1049089   0 Aug 25 11:20 ./
drwxr-xr-x 1 san 1049089   0 Aug 25 11:19 ../
-rw-r--r-- 1 san 1049089  14 Aug 25 11:20 COMMIT_EDITMSG
-rw-r--r-- 1 san 1049089 208 Aug 17 13:51 config
-rw-r--r-- 1 san 1049089  73 Aug 17 11:11 description
-rw-r--r-- 1 san 1049089  23 Aug 17 11:11 HEAD
drwxr-xr-x 1 san 1049089   0 Aug 18 17:15 hooks/
-rw-r--r-- 1 san 1049089 217 Aug 25 11:20 index
drwxr-xr-x 1 san 1049089   0 Aug 18 17:15 info/
drwxr-xr-x 1 san 1049089   0 Aug 18 17:15 logs/
drwxr-xr-x 1 san 1049089   0 Aug 25 11:20 objects/
drwxr-xr-x 1 san 1049089   0 Aug 18 17:15 refs/

There's a refs folder: let's take a look inside:

[6] ~/grocery (master)
$ ll .git/refs/
total 4
drwxr-xr-x 1 san 1049089 0 Aug 18 17:15 ./
drwxr-xr-x 1 san 1049089 0 Aug 25 11:20 ../
drwxr-xr-x 1 san 1049089 0 Aug 25 11:20 heads/
drwxr-xr-x 1 san 1049089 0 Aug 17 11:11 tags/

Now go to heads:

[7] ~/grocery (master)
$ ll .git/refs/heads/
total 1
drwxr-xr-x 1 san 1049089  0 Aug 25 11:20 ./
drwxr-xr-x 1 san 1049089  0 Aug 18 17:15 ../
-rw-r--r-- 1 san 1049089 41 Aug 25 11:20 master

There's a master file inside! Let's see what's the content:

[8] ~/grocery (master)
$ cat .git/refs/heads/master
0e8b5cf1c1b44110dd36dea5ce0ae29ce22ad4b8

As you could imagine, Git manages all this articulated reference system... with a trivial text file! It contains the hash of the last commit made on the branch; in fact, if you look at the previous git log output, you can see the hash of the last commit is 0e8b5cf.

Nowadays it has been time since the first time, but I continue to be amazed by how essential and effective the internal structure of Git is.

主站蜘蛛池模板: 榆树市| 永德县| 岗巴县| 垫江县| 华宁县| 泰州市| 同仁县| 济南市| 丘北县| 永仁县| 二连浩特市| 黄大仙区| 邵东县| 贵德县| 本溪| 集安市| 郯城县| 龙川县| 米林县| 石阡县| 寻甸| 隆德县| 大港区| 铁力市| 泉州市| 镇江市| 崇礼县| 沙河市| 景东| 那坡县| 色达县| 兴宁市| 胶南市| 文安县| 阿荣旗| 水富县| 扎赉特旗| 积石山| 汉源县| 安溪县| 灌阳县|