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

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.

主站蜘蛛池模板: 湄潭县| 大埔区| 湾仔区| 吉木乃县| 蓝山县| 曲沃县| 潢川县| 武冈市| 涪陵区| 广安市| 大竹县| 宁化县| 克东县| 本溪市| 金寨县| 德化县| 海宁市| 安吉县| 阿坝| 尖扎县| 西充县| 建宁县| 宁晋县| 万州区| 胶南市| 南京市| 南开区| 新晃| 桂东县| 精河县| 北票市| 嘉祥县| 剑河县| 安图县| 雅安市| 吴堡县| 福安市| 民权县| 丰顺县| 岑溪市| 门源|